I receive a text with linebreaks from an API but I can't get the linebreaks to work.
This is a part of the text I want to shown. http://pastebin.com/CLnq16mP (pasted it there because the formatting on stackoverflow wasnt correct.)
I tried this:
termsAndConditionsTextView.setText(Html.fromHtml("<html><body>" + textResponse.getText() + "</body></html>"));
and this:
termsAndConditionsTextView.setText(Html.fromHtml(textResponse.getText()));
but the linebreaks (\r\n) and spaces are always ignored.
How can I fix this?
Since its html try using
</br>
You can replace all \r\n and spaces in your text by doing something like this:
//message is your string.
message = message.replace("\r\n","<br />");
message = message.replace(" "," ");
termsAndConditionsTextView.setText(Html.fromHtml(message));
Good Luck!
As the text is pre-formatted, even with indentation, you could use the <pre>
tag.
<pre>
your text.
</pre>
But the newlines evidently where escaped: \r\n
so you still have to convert:
message = message.replace("\\r\\n", "\r\n");
The same holds for \/
.
If you want to introduce bold, hyperlinks and such, then the <pre>
tag fails, as it can only contain preformatted as-is text,
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