2014-10-07 45 views
1

我正在尝试为应用程序编写UiAutomator测试。 在这里我有一堆textviews里面我想从中提取文本并将其存储在ArrayList中的相关布局。以便我可以将该ArrayList与预期的结果列表进行比较。如何从相对布局中提取文本并将其存储在ArrayList中

有关如何操作的建议?

+1

来自相对布局的文本? Edittexts或TextViews? – 2014-10-07 06:13:30

+0

如何在'RelativeLayout'上写文字? – MilapTank 2014-10-07 06:26:50

+0

对不起,我忘了提及它的TextViews – shuks 2014-10-07 06:27:59

回答

2

您可以迭代RelativeLayout的所有子节点并获取其文本。

for(int i=0; i< relLayout.getChildCount(); i++) { 
    TextView textView = (TextView) relLayout.getChildAt(i); 
    String text = textView.getText().toString(); //put text in an ArrayList<String> as per your need 
} 

希望这可以帮助你。

+0

谢谢!有效 – shuks 2014-10-08 04:56:12