Tuesday 27 September 2016

Html List tag not working in android textview. what can i do?



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.
  • Trim, tailored fit for a bespoke feel
  • Medium spread collar, one-button mitered barrel cuffs
  • Applied placket with genuine mother-of-pearl buttons
  • ;Split back yoke, rear side pleats
  • Made in the U.S.A. of 100% imported cotton.
";


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");

Answer



As you can see in the Html class source code, Html.fromHtml(String) does not support all HTML tags. In this very case,

    and
  • 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="A dressy take on classic gingham in a soft, textured weave of stripes that resembles twill.  Take a closer look at this one.
    • Trim, tailored fit for a bespoke feel
    • Medium spread collar, one-button mitered barrel cuffs
    • Applied placket with genuine mother-of-pearl buttons
    • ;Split back yoke, rear side pleats
    • Made in the U.S.A. of 100% imported cotton.
    ";
    webView.loadDataWithBaseURL(null, str, "text/html", "utf-8", null);


No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...