Search code examples
androidtextviewcharsequence

How to change the android:text of a textView


I am having trouble changing the text inside my textview. I want to have the textview contain the string "foo \n bar \n foo2 \n bar2" and I want to be able to add and take away lines from the textview. I can manually type in "foo \n bar" in the android:text, but I would like to edit it from my class file and append items added from an ArrayList of Strings.

It want's to take in a CharSequence, but converting from String to CharSequence doesn't seem to make it very happy.


Solution

  • You should be able to pass a string to the TextView's setText method once you have a reference to it...

    TextView text=(TextView)findViewById(R.id.textviewID);
    text.setText("foo \n bar");
    

    will work (replace R.id.textviewID with the id of your control, of course)