1

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?

fregomene
  • 155
  • 1
  • 11
  • What is the declaration for `placeDescription`? – Code-Apprentice May 14 '17 at 20:33
  • @Code-Apprentice public static String placeDescription; – fregomene May 14 '17 at 20:41
  • I have a quasi unrelated to your problem: why is the variable static? I think you can declare it as a local variable in the method where you use it. – Code-Apprentice May 14 '17 at 20:43
  • @ Code-Apprentice I use it several times. This will not help – fregomene May 14 '17 at 20:51
  • This is an incorrect use of static. You are right that it will not fix your problem. You should still learn how to use static correctly. – Code-Apprentice May 14 '17 at 20:52
  • Possible duplicate of [How to display HTML in TextView?](http://stackoverflow.com/questions/2116162/how-to-display-html-in-textview) – Code-Apprentice May 14 '17 at 21:01
  • @Code-Apprentice Look, my question is clear and you left tons of comments. None of your comments were useful. And my question is not a duplicate as those answers didn't fit. Do you have any idea of how to substitute method Html.fromHtml()? – fregomene May 14 '17 at 21:56
  • Please [edit] your question to explain how what you want to do is different from the linked question. Using the example HTML in your question, what do you want to show in the TextView? Give a specific example. – Code-Apprentice May 14 '17 at 22:12
  • @Code-Apprentice This String should be an answer: 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. Visitors will be able то live through with Klitschko brothers many moments of their lives. – fregomene May 14 '17 at 22:18
  • Please edit your question – Code-Apprentice May 14 '17 at 22:19
  • The answers to the linked question as well as mine here will do exactly what you want. – Code-Apprentice May 14 '17 at 22:20
  • @Code-Apprentice The question is clear. Still none of your answers removed
    tags
    – fregomene May 14 '17 at 22:21
  • please reply to my last comment below my answer – Code-Apprentice May 14 '17 at 22:28

1 Answers1

1

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);
Code-Apprentice
  • 81,660
  • 23
  • 145
  • 268