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?

1
  • no it's not a duplicate, with fromHtml i get a string fully parsed from Html, i want to parse all html tags except the img tag Commented Apr 10, 2014 at 12:57

3 Answers 3

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.

Sign up to request clarification or add additional context in comments.

Comments

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)));

2 Comments

it's for messages, like chat, so i can't have a strings.xml about it
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"));

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.