2

I am using a TextView to show some text I have formatted from HTML:

Spanned s = Html.fromHtml(getString(R.string.disclaimer));
tvDisclaimer.setText(s);

The text is in the strings.xml using CDATA:

<string name="disclaimer">
    <![CDATA[
    <p>blablabla</p>
    <ul>
      <li>foo
      <li>bar
    </ul> 
    ]]>
</string>

The point now, is that the whole thing crashes with an IndexOutOfBoundsException in Choreographer. It works for some simple HTML, but at some point, I only have to add one character (ø) to have it crash. Removing the character makes it work.

If Html.fromHtml() is not the way to go, what could I use to get some decent rich text in my app?

4
  • Are you using the html char code or directly the char ? Commented Oct 9, 2012 at 21:03
  • Directly the char. But in other places, the char works fine. Commented Oct 9, 2012 at 21:05
  • Since <ul> and <li> are not supported by Html.fromHtml(), you have bigger problems. Commented Oct 9, 2012 at 22:13
  • @CommonsWare, okay thanks. Too bad that is not found in the docs. Plus, I would like to have a HtmlNotSupportedException or something alike. Or at least an exception in Html.fromHtml. Now I get some strange error in a strange place. /rant Commented Oct 10, 2012 at 6:35

2 Answers 2

1

I figured out how to do it. As already stated in the comments, the Html.fromHtml() method only supports a limited set of HTML. It can be accomplished by using a WebView:

    WebView wvDisclaimer = (WebView)findViewById(R.id.wvDisclaimer);
    wvDisclaimer.loadDataWithBaseURL("about:blank", 
            getString(R.string.disclaimer), "text/html", "utf-8", "about:blank");
Sign up to request clarification or add additional context in comments.

Comments

0

I fixed this issue by using below codes:

<string name="disclaimer">
<![CDATA[
<p>blablabla</p>
    <br>&#8226; &nbsp;foo
    <br>&#8226; &nbsp; bar
]]>
</string>

Hope it helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.