java Android Spanned Html.fromHtml(stringWithCDATA) still shows tags as text

1.2k views Asked by At

Usually I use <![CDATA[..here's text]]> in my Resources Strings so when I do

Spanned sp=Html.fromHtml(getResources.getString(R.string.myString));
myTextView.setText(sp);

I get text with all the tags like ,
etc working as they should.

but now I build String during some metod like :

String result="<![CDATA[";
//some code
result+="<b>Chapter :"+chapterNumber+"</b><br /><br />"
//some other additions and in the end
result+="]]>";

Spanned sp = Html.fromHtml(result);
myTextView.setText(sp);

and I see all my tags on the screen instead of them being implemented, like : Chapter :1

...

I tried to use StringBuilder instead, but result is the same.

What should I do for the tags to word right in my case?

1

There are 1 answers

2
CommonsWare On BEST ANSWER

What should I do for the tags to word right in my case?

Get rid of the CDATA:

Spanned sp = Html.fromHtml("<b>Chapter :"+chapterNumber+"</b><br /><br />");
myTextView.setText(sp);