0
    sv = (ScrollView) findViewById(R.id.sv);// sv == tv parent view
    tv = (TextView) findViewById(R.id.tv);
    tv.setMaxLines(10);
    for(int i=0;i<10;i++)
    {
        String t1 = "---------------------"+i+"--------------- \n";
        tv.append(t1);
    }
    tv.append("dddddddddddddddddd \n");// 11 line

this is game chat panel ,when chat info excessive ,Whether can delete old lines ,Such as lines > 500 delete 1-200 line or delete 1 line update new 501 line ?

2 Answers2

0

You can add scroll inside of textView with:

android:scrollbars="vertical"

or You can delete first line with this before adding 11th line according to your code:

String arr[] = myTextView.getText().toString().split("\n",2);
myTextView.setText(arr[1]);
invisbo
  • 3,399
  • 1
  • 16
  • 20
0

Instead of a huge TextView, consider using a ListView with a circular buffer adapter that caps the number of rows (messages) efficiently and enables smooth scrolling.

Community
  • 1
  • 1
laalto
  • 150,114
  • 66
  • 286
  • 303