2014-10-07 44 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

相關問題