I am using a TextView for log purposes inside an Android app, and if it gets too long the app becomes unstable. Is it possible to set a max limit so TextView removes old text after it gets to a certain size? If not I can set the app to automatically clear the text once a day. If I want to clear the text manually, do I call TextView.clearComposingText();
?
Asked
Active
Viewed 218 times
1

david
- 997
- 3
- 14
- 34
-
Don't you think using a file for logs will be a better idea ? – Vivek Mishra Sep 03 '18 at 12:20
-
no, because I want to be able to see the logs conveniently. The logs are for short term only. – david Sep 03 '18 at 12:21
-
How about combininig maxLines and answer from this link https://stackoverflow.com/questions/12037377/how-to-get-number-of-lines-of-textview – Vivek Mishra Sep 03 '18 at 12:24
-
Save your log's inside a file and when needed show the some part of the file inside a textview – Amir Hossein Mirzaei Sep 03 '18 at 12:27
1 Answers
1
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLength="100"/>
Set the maximum length of the textview to a limit number and also check when to clear the textview. Write the following function in Activity and call it on onCreate.
private void checklength(){
if(textview.getText().length()==100){
textview.setText("");
}
}
Hope it helps.

Dipin P J
- 58
- 8