0

This is given string.

String a=<p><strong>Test</strong></p>\r\n<p>&nbsp; &nbsp; &nbsp; &nbsp; Test description</p>

How to convert this string to display and store in textview?

I used like this. But it is not working.

    TextView textView;
    textview.setText((Html.fromHtml(a).toString()));

This gives output like this:

   <p>strong>Test</strong></p><p>&nbsp;&nbsp;Test description</p>

How to set as proper String in textview?

2 Answers 2

1

For this you can use Jsoup

String normailString = Jsoup.parse(htmlString).text();
Sign up to request clarification or add additional context in comments.

3 Comments

thanks will you please put like this. String htmlString=Html.fromHtml(a).toString()). so that it may help for some others in future. i will accept your answer after you done like this.
whether it's possible to do without using jsoup?
Actually 'Html.fromHtml(a).toString()' is working perfectly for me, i dont know what happened in your case. Make sure Imported is 'android.text.Html'.
0

You must uses This Tag in your string.xml File :

<![CDATA[<h1><strong>YOUR HTML CODE HERE</strong></h1> ]]>

Or Try adding the CDATA Tag in your String Variable

2 Comments

i am getting from server response through json and storing in strings and converting that. how i can use that in strings.xml?
String a = "<![CDATA" + Your Html String + "]]>" ; i've not tried at RunTime but i uses Html in string.xml file like this

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.