-3

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.

Mac
  • 15
  • 3

2 Answers2

0

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)

Chris
  • 22,923
  • 4
  • 56
  • 50
0

You can convert CharSequence to string just by invoking toString() method on CharSequence object.

Further you can set Text on TextView by using setText() method as follow:

TextView tv=(TextView)findViewById(R.id.textview1);
tv.setText(charSequenceObj.toString());

If you are trying to print "\n" too (as your question is not bit clear to me.) use escape sequence characters. so for "\n" it will be "\n"