I am using webservice in my android application. In my webservice result I get a HTML formatted String as result.
Assume this is my web service result:
Books on Chennai:\n
I am using Html.fromHtml(String) to add this to my TextView. But I am not getting new line feature. I displays it as a paragraph.
Books on Chennai: Madras Discovered, Tales of Old and New Madras, Madras (1992) by S. Muthiah Madras – its Past and its Present (1995) by S. Muthiah Madras – its Yesterdays and Todays and Tomorrows by S. Muthiah At Home in Madras (1989) by S. Muthiah The Spirit of Chepauk (1998) by S. Muthiah The Story Of Fort St. George (1945) by Col. D.M. ReidFiction set in Chennai Kalyani’s Husband by S.Y. Krishnaswamy Chasing Rainbows in Chennai (Chasing Rainbows in Chennai), (2003) by Colin Todhunter In Old Madras (1914) by Bithia Mary Crocker
How can I present this data in an easily readable and understandable way?
for the new line in TextView just add \n in middle of your text it works..
Add Line Breaks to a TextView Just add a \n to your text. This can be done directly in your layout file, or in a string resource and will cleanly break the text in your TextView to the next line.
This tag makes the EditText be at most x many lines tall as specified as value. It accepts an integer value. Note : For multiline EditText by default the cursor and hint text is displayed in the center, you can use android:gravity attribute to set it at top and left of the EditText view : android:gravity="top|left"
Having this string as an example:
String sBooks = "Books on Chennai:\n ....";
Replace: \n
with <br>
:
sBooks = sBooks.replace("\n", "<br>");
Example using a TextView
:
myTextView.setText(Html.fromHtml(sBooks));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With