0

If I have html with tags not supported as part of Html.fromText I understand a WebView will do the trick as it supports standard HTML as a browser but its performance is really slow to my liking. So if I don't want to use WebView, the only other way is to parse the HTML myself and put different tags in muliple TextView inside a vertical LinearLayout?

Prasanna
  • 3,703
  • 9
  • 46
  • 74
  • I believe the Android OS takes care of parsing the tags in a TextView. Have you tried displaying it in a TextView? – Sana Mar 26 '12 at 17:45
  • That would depend a bit on the "tags not supported" that you want to support. There is no way you are going to support ` – CommonsWare Mar 26 '12 at 17:47
  • @Sana Yes I tried displaying it in `TextView` and it did not render. @CommonsWare I am trying to support
     and  which are not getting rendered in `TextView`
    – Prasanna Mar 26 '12 at 17:49

2 Answers2

4

You'll have to use Html.fromHtml() with an Html.TagHandler to handle unknown tags like <pre/> and <code/>.

See this answer for an example of how to implement Html.TagHandler.

Community
  • 1
  • 1
Dheeraj Vepakomma
  • 26,870
  • 17
  • 81
  • 104
1

Use replaceAll() to convert the <pre> and <code> tags to <tt>, which is supported by Html.fromHtml(). Then, use Html.fromHtml() to create the SpannedString that you pass to the TextView.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491