简体   繁体   English

在Android中访问Multiline TextView的文本

[英]Access text of Multiline TextView in Android

I want to access text of particular line in a multi-line TextView. 我想在多行TextView中访问特定行的文本。 Any suggestions on how I could do this? 有关如何做到这一点的任何建议?

Fetch the Layout ( android.text.Layout ) of the TextView by calling mTextView.getLayout(); 通过调用mTextView.getLayout()获取TextView的Layout( android.text.Layout ); There you can for instance use the getLineStart or getLineEnd methods to get the offset of the text. 例如,您可以使用getLineStart或getLineEnd方法来获取文本的偏移量。 That combined with getText and used using normal String operations should probably be enough for u! 结合getText并使用普通的String操作应该对你来说应该足够了!

By default, text view is multi line. 默认情况下,文本视图是多行的。 Set the text with new line characters for ex. 使用新行字符设置文本。 "First line \\nSecond line". “第一行\\ n第二行”。

Another option is listed here : https://stackoverflow.com/questions/2610280/how-to-get-multi-line-text-on-a-button-in-android 此处列出了另一个选项: https//stackoverflow.com/questions/2610280/how-to-get-multi-line-text-on-a-button-in-android

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM