Reputation: 4222
I am saving some text in mysql db (longtext type) which contains new line character something like:
Hello World
This is a test
Thanks
I am sending value in db via php like this:
$message = 'Hello World' . "\n";
$message .= 'This is a test' . "\n";
$message .= 'Thanks;
I can see that new line character is saved in db and it shows fine.
However in TextView I see all text joined, there is no new line character. This is how TextView shows it:
Hello WorldThis is a testThanks
What I have tried:
android:singleLine="false"
msg.replaceAll("\n", System.getProperty("line.separator"))
FYI, if i type same message containing new line in android application itself then TextView shows newline characters correctly but it is just not getting new line character coming from mysql db :(
Thanks for the help
Upvotes: 0
Views: 1034
Reputation: 18112
Replace \n with "html br tag" and
use this method yourTextView.setText(Html.fromHtml(text));
Upvotes: 0
Reputation: 17140
use
msg.replaceAll("\n","<br />");
then on the text view use
myTextView.setText(Html.fromHtml(msg));
Upvotes: 2