开发者

Android TextView: Clear text on current line

开发者 https://www.devze.com 2023-04-06 14:14 出处:网络
I\'m working on a telnet client, it uses one TextView to display the text from the telnet session by appending the new text to the TextView.

I'm working on a telnet client, it uses one TextView to display the text from the telnet session by appending the new text to the TextView.

This works great, however telne开发者_高级运维t can send codes which tells the client app to clear the text on the current line and I can't see any way to do this with an Android TextView?


if you want to clear some specific line than

//this will help you to put textview with the text of the current line textview.setText(textview.getText().toString().substring(from 0 to the last occurance of newline?)) but not to delete that line, it does the reverse thing

if you want to clear just the current line you need to delete that line, which the current line can refer to two things: 1. the first line 2. the last line , for example if you use you text view like an output from a console than you need to delete the last line not the first line

  1. to delete firs line just start searching '\n' and when you find than take the index of it, than do substring textview.setText(textview.getText().toString().substring(from index to the end))

  2. find the index of the last occurance of new line and than textview.setText(textview.getText().toString().substring(from 0 to the index))

so when you receive code for clearing the current line than just implement algorithm for one of the scenarios above

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号