Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to format a string for a textview android

I have a TextView and when I call .setText(string), it displays the string exactly as it is. For instance, if the string contains " ' " , ' will be displayed.

How can I fix this?

like image 571
Radu Avatar asked Nov 19 '25 13:11

Radu


2 Answers

Looks like your outside source already does the convertion from ' to ' since regular single quote will be displayed just fine in a TextView. What you can to do in this case is:

yourTextView.setText(Html.fromHtml(stringSource));

where stringSource is your string that comes from outside source. This will take care of more than just the single quote character.

like image 63
Voicu Avatar answered Nov 21 '25 02:11

Voicu


The single quote ' in java needs to be escaped using a backslash (\). You can find other characters that need to be escaped here.

like image 41
Edenane Avatar answered Nov 21 '25 03:11

Edenane



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!