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?

Star
  • 735
  • 3
  • 13
  • 34

2 Answers2

1

For this you can use Jsoup

String normailString = Jsoup.parse(htmlString).text();
Remees M Syde
  • 2,564
  • 1
  • 19
  • 42
  • 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. – Star Jan 25 '15 at 19:26
  • whether it's possible to do without using jsoup? – Star Jan 25 '15 at 19:39
  • 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'. – Remees M Syde Jan 25 '15 at 19:40
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

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