2

is it possible to parse a string with html tags (like br, &nbsp, the accented letters, ..) without parsing the image tag ? If yes , how can i do It?

3 Answers3

1

Depends on what you are going to do with that parsed string. If you need to display it in a TextView, then you could use

textView.setText(Html.fromHtml(yourString, customImageGetter, null));

Where customImageGetter is your subclass of Html.ImageGetter which returns empty drawables in getDrawable(String source) method. Empty drawable could be an 1x1 transparent image.

Const
  • 976
  • 7
  • 11
0

Define the html string in strings.xml and use this

<string name="about">
    <![CDATA[
    <html>
    <head></head>
    <body style="text-align:justify;">

    </body>
    </html>
    ]]>

tv.setText(Html.fromHtml(getString(R.string.about)));

Karthik
  • 2,282
  • 2
  • 22
  • 23
0

I guess this would work. 1. Initially, in the html tags instead of using <img> </img>, you will have to use <image> </image>

strTemp ="<h2>Title</h2><br><p>Description here</p> <image src='source here'></image>";

2.

Spanned sp = Html.fromHtml( strTemp );

3.

textView.setText(sp.toString().replace("image", "img"));
ngrashia
  • 9,869
  • 5
  • 43
  • 58