Skip to content Skip to sidebar Skip to footer

Android App Not Rendering Html Tags Very Well

This is what i am getting from web service in string. <p><strong>This is instructor&#39;s reply to the guest&#39;s MDB message</

Solution 1:

It may help you I was also getting same issue in my project and this worked for me.may be it will help you:

Stringreply= parent.getString(TAG_ReplyMessage);
TextViewReplyTextView= findViewById(R.id.reply_txt);
Stringhtmltext= Html.fromHtml(reply).toString();
ReplyTextView.setText(Html.fromHtml(htmltext));

Solution 2:

Android does not support all HTML tags.

This is a, albeit a bit old, list of supported HTML tags: http://www.grokkingandroid.com/android-quick-tip-formatting-text-with-html-fromhtml/

Or you could look through the sources and see which are supported: http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/5.1.1_r1/android/text/Html.java#Html

According to those lists, <p> is not supported. So it can't parse anything within <p></p>.

Solution 3:

&amp;#39; remove amp; part. Html code for ' single quote is just &#39;

Solution 4:

You can write those tags directly between <![CDATA[...]]> in strings.xml.

Example:

<stringname="type"><![CDATA[Type:<B> %s</B>]]></string>

In Java:

textView.setText(Html.fromHtml(getString(R.string.type, "Sports")));

Output:

Type: Sports

Update:

If string itself is like:

String data = "&lt;p&gt;&lt;strong&gt;This is instructor&amp;#39;s reply to the guest&amp;#39;s MDB message&lt;/strong&gt;&lt;/p&gt;";

Then, you can try as below:

textView.setText(Html.fromHtml(Html.fromHtml(data).toString()));

Post a Comment for "Android App Not Rendering Html Tags Very Well"