4

I am facing a weird issue:

My source string for Html.fromHtml() is as follows:

<strong>Terrible experience with Nikko hotel</strong><br />It was not easy to cancel booking. I called to cancel books, but they still chraged us two full days. A reason was we were late ten minutes in calling to cancel. They explained us very kindly that I can only cancel the first day. But they charged after then.\nSick."

which is retrieved from a json response

Now, when I display it using setText as follows:

commentbox.setText(Html.fromHtml(cmnt.getString("cmnt")));

but the output which i see is as follows:

enter image description here

Why is it giving me italic text instead of bold?

5
  • Try to increase the width of the textview so your strong text to fit in 1 line and see what's happening :) Commented Nov 25, 2011 at 7:31
  • width is wrapcontent, that shouldnt be an issue , its happening at other places too :( Commented Nov 25, 2011 at 7:34
  • hm... remove the strong and replace it with <b> tags and see what's happening :) Commented Nov 25, 2011 at 7:38
  • 1
    sadly , its a json response from a server, can try replacing <strong> with <b> or <em>..thanks Commented Nov 25, 2011 at 7:41
  • Check for the supported tags list javatechig.com/2013/04/07/how-to-display-html-in-android-view Commented Apr 7, 2013 at 20:53

1 Answer 1

8

This can be a LIMITATION as described here:

the Html.fromHtml() method in Android that creates a SpannedString from HTML source flips <em> and <strong> tags, so what you might be used to seeing in boldface turns into italics and vice-versa. This should only be an issue if you are displayng the generated HTML in a TextView — WebView in particular should behave more normally.

Sign up to request clarification or add additional context in comments.

2 Comments

i hv found an issue here also you can use <b> instead
thanks, wil hav to check for tags and then reverse it before using fromHtml()

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.