0

By that, i mean if a String contains HTML tags like <br></br> they must be converted to \n.

I tried this:

String formatted = android.text.Html.fromHtml(nonFormatted).toString();

But this seems to just remove all the HTML tags.

Input:

String nonFormatted = "<ul><li>Android v4.0 (Ice Cream Sandwich) OS<\/li><li>2 MP Primary Camera<\/li><li>3-inch TFT Capacitive Touchscreen<\/li><li>850 MHz Processor<\/li><li>QWERTY Keypad<\/li><li>FM Radio<\/li><li>Wi-Fi Enabled<\/li><li>Expandable Storage Capacity of 32 GB<\/li><\/ul>";

Output after using android.text.Html.fromHtml(nonFormatted).toString();

String formatted = Android v4.0 (Ice Cream Sandwich) OS2 MP Primary Camera3-inch TFT Capacitive Touchscreen850 MHz ProcessorQWERTY KeypadFM RadioWi-Fi EnabledExpandable Storage Capacity of 32 GB

But on the website it looks like this:

enter image description here

I want my java String to be like the one in the image, instead of bullets, a new line character.

Thank You

3 Answers 3

1

Because Html.fromHtml(string) just support some html tags like: br p div em b strong a u sup sub... but it doesn't support ul, li tags so you can try to display these tags using WebView or TagHandler. "TagHanlder is notified when HTML tags are encountered that the parser does not know how to interpret".These links will show you how to do that:

Show <ul> <li> in android textview

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

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

Comments

0

You need to make some parsing to properly replace the tags for whitespaces generically.. try exploring jsoup, it is a very powerful library that allows you to whitelist tags, clean up HTML, select and find tags, removing, etc.

Comments

0

A simple regular expression replace could sove this issue. http://docs.oracle.com/javase/6/docs/api/java/util/regex/Pattern.html

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.