Android TextView:清除当前行上的文本
我正在开发一个 telnet 客户端,它使用一个 TextView 通过将新文本附加到 TextView 来显示 telnet 会话中的文本。
这很好用,但是 telnet 可以发送代码告诉客户端应用程序清除当前行上的文本,而我看不到任何方法可以使用 Android 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 telnet 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想清除某些特定行,
//这将帮助您将 textview 与当前行的文本一起放置
textview.setText(textview.getText().toString().substring(从 0 到最后一次出现换行符?))
但不是删除该行,
如果您只想清除当前行,则需要删除该行,它会执行相反的操作,当前行可以指两件事:
1.第一行
2. 最后一行,例如,如果您使用文本视图(如控制台的输出),则需要删除最后一行而不是第一行
要删除第一行,只需开始搜索 '\n' ,当您找到比获取它的索引,比获取子字符串
textview.setText(textview.getText().toString().substring(from index to the end))
查找最后一次出现新行的索引并比
textview.setText(textview.getText().toString().substring(from 0 to the index))
因此,当您收到清除当前行的代码时,不仅仅是为上述场景之一实现算法
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
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))
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