0

This is what i am getting from web service in string.

<p><strong>This is instructor's reply to the guest's MDB message</strong></p>

This is how i am setting it to text view

String Reply = parent.getString(TAG_ReplyMessage);
TextView ReplyTextView= (TextView) findViewById(R.id.reply_txt);
ReplyTextView.setText(Html.fromHtml(Reply));

but app shows information with <p> and <strong> tags.

enter image description here

Whereas it should render those tags, not to display it's html.

Any help would be highly appreciated.

4 Answers 4

2

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

String reply = parent.getString(TAG_ReplyMessage);
TextView ReplyTextView = findViewById(R.id.reply_txt);
String htmltext = Html.fromHtml(reply).toString();
ReplyTextView.setText(Html.fromHtml(htmltext));
Sign up to request clarification or add additional context in comments.

Comments

0

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>.

Comments

0

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

Comments

0

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

Example:

<string name="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()));

1 Comment

Well i am getting that string from web service. why i need to add it to strings.xml

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.