Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Html List tag not working in android textview. What can I do?

Tags:

android

Html List tag not working in android TextView. This is my string content:

String str="A dressy take on classic gingham in a soft, textured weave of stripes that resembles twill.  Take a closer look at this one.<ul><li>Trim, tailored fit for a bespoke feel</li><li>Medium spread collar, one-button mitered barrel cuffs</li><li>Applied placket with genuine mother-of-pearl buttons</li><li>;Split back yoke, rear side pleats</li><li>Made in the U.S.A. of 100% imported cotton.</li></ul>"; 

I loaded it in a text view like this:

textview.setText(Html.fromHtml(str)); 

The output looks like a paragraph. What can I do? Is there any solution for it?

Edit:

webview.loadData(str,"text/html","utf-8"); 
like image 946
Praveen Avatar asked Jun 30 '10 14:06

Praveen


People also ask

How do I view HTML code in Android?

Here is the simple solution to show HTML in TextView in android. Step 1 − Create a new project in Android Studio,go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.

Can I use HTML in Android Studio?

You can add HTML in Android Studio by creating an assets folder and inserting your HTML here.

Which tag is used to end an android list?

</UL> tag is used to end an unordered list.


1 Answers

As you can see in the Html class source code, Html.fromHtml(String) does not support all HTML tags. In this very case, <ul> and <li> are not supported.

From the source code I have built a list of allowed HTML tags:

  • br
  • p
  • div
  • em
  • b
  • strong
  • cite
  • dfn
  • i
  • big
  • small
  • font
  • blockquote
  • tt
  • monospace
  • a
  • u
  • sup
  • sub

So you better use WebView and its loadDataWithBaseURL method. Try something like this:

String str="<html><body>A dressy take on classic gingham in a soft, textured weave of stripes that resembles twill.  Take a closer look at this one.<ul><li>Trim, tailored fit for a bespoke feel</li><li>Medium spread collar, one-button mitered barrel cuffs</li><li>Applied placket with genuine mother-of-pearl buttons</li><li>;Split back yoke, rear side pleats</li><li>Made in the U.S.A. of 100% imported cotton.</li></ul></body></html>"; webView.loadDataWithBaseURL(null, str, "text/html", "utf-8", null); 
like image 94
Cristian Avatar answered Sep 21 '22 07:09

Cristian