android - 我有一个文本视图,但我需要根据行的数据。前 4 行、3 行等
问题描述
我有一条来自 QR 码的文本。文本模式是这样的,整个文本位于 textview 中:
abc Ahtasham 在那里 def 不在那里 110 是 不是 120 等等等等
TEXTFEILD “abc”(必填) 免费 TEXTFIELD 用于地址
TEXTFIELD “def”(必填) 联系人免费 TEXTFIELD
我需要将前四行放在 textview 中,其他 2 行放在其他 textview 中,另外 2 行放在另一个 textview 中。我想知道如何在线获取数据。任何人都可以帮助。谢谢你。
解决方案
像这样做
private String getLines(String txt, int aFrom, int aTo) {
// create an array with all lines
String[] lines = txt.split("\\r?\\n");
String result = "";
for (int i = aFrom; i <= aTo; i++)
result += lines[i] + "\n";
return result;
}
像这样使用
textV2.setText(getLines(textV1.getText(), 0, 3)); // get first 4 lines
textV3.setText(getLines(textV1.getText(), 4, 5)); // get next 2 lines
// and so on..
推荐阅读
- javascript - 如何通过 id/key 从 sessionStorage 访问记录?
- mysql - MySQL 未处理的拒绝错误,无默认值
- android - 5 次按钮单击以更改对象颜色 五种不同的连续颜色
- c# - 内部有内容的元素的 XPath?
- mysql - mysql 创建生成的列并删除特定字符
- wpf - 如何设置 ListViewItem 选定的背景颜色?
- java - RichTextFX 的撤消无法正常工作
- javascript - Dexie modify() 失败而不抛出错误
- java - 子类可以使用相同的方法,但使用不同的变量类型吗?如何?(JAVA)
- android - 选择查询 - 如何?