Вопрос

I want to set text for a textView by code. My text is something like this :" aaaa \n bbb\n ccc" and if I use setText() method on screen I got exact in this format, and not like this :

"aaaa
bbb
ccc".

If I put in xml android:text="aaaa \n bbb\n ccc" it works fine. I need to set this by code,and not from xml file. How can I do this?

Это было полезно?

Решение

Simply use the newline character "\n", like this:

myTextView.setText("aaaa\nbbb\nccc");

That will output:

aaaa
bbb
ccc

Другие советы

Use HTML tags:

myTv.setText(Html.fromHtml("<p>aaaa<br/>bbbb<br/>cccc</p>"));

Try like this:

setText("aaaa\nbbb\nccc");
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top