Search code examples
androidtextviewsettext

SetText to a TextView


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?


Solution

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

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

    That will output:

    aaaa
    bbb
    ccc