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:
String sBooks = "Books on Chennai:\n ....";
Replace: \n
with <br>
:
sBooks = sBooks.replace("\n", "<br>");
Example using a TextView:
myTextView.setText(Html.fromHtml(sBooks));
The best option is instead of TextView
use a WebView
and
final String mimeType = "text/html";
final String encoding = "UTF-8";
webView.loadDataWithBaseURL("", contentToShowString, mimeType,
encoding, "");
Just replace \n
with <br/>
tag and then pass the whole string to Html.fromHtml(String)
. By this it will be displayed in proper format.
You should replace this \n
with <br>
. For more android HTML
tags support go to Android Support HTML Tags or daniel-codes.blogspot.in
Use this:
b.setText(Html.fromHtml("<b>" + your string+ "</b>" + "<br/>" + cursor.getString(1)));
have you tried with \r\n ?`
If this not works then you can try with :
\n
with escape sequence : \\\n
I hope this will help you :)
Something like this
string = string.replace("\\\n", System.getProperty("line.separator"));