fregomene
fregomene

Reputation: 155

How to convert HTML text into a String and set it into a TextView in android?

I know that there are several similar topics already created, but I still haven't found an answer. I receive an HTML in JSON and need to clean it up from tags and set this clean String as a TextView. Unfortunately, standard Android method Html.fromHtml() doesn't work properly, it doesn't remove all tags. For example:

1) HTML text: <div>At the exhibition everyone can watch a documentary about the life of boxers and see the modern multimedia show which translates on the interactive screens.</div>\r\n \r\n<div>Visitors will be able то live through with Klitschko brothers many moments of their lives.

2) After converting it into a String placeDescription = Html.fromHtml(obj.getString("detail_text")).toString();
the text is the same with tags. What am I doing wrong? Are there any tools/libraries that can help me?

Upvotes: 1

Views: 650

Answers (1)

Code-Apprentice
Code-Apprentice

Reputation: 83527

I assume you want to display the HTML content without all the tags like in a browser. To do this, change

placeDescription = Html.fromHtml(obj.getString("detail_text")).toString();

to

CharSequence placeDescription = Html.fromHtml(obj.getString("detail_text"));

Then you need to call

myTextView.setText(placeDescription);

Upvotes: 1

Related Questions