1:我有一個列表視圖如下:Robotium獲取文本爲ListView
sort
game
play
home
我們怎樣才能得到上面列出的所有文本或者一個接一個或所有robotium。
2:有沒有什麼辦法,我們能夠在SD卡(模擬器)來創建一個文件。
請建議一種方法。
1:我有一個列表視圖如下:Robotium獲取文本爲ListView
sort
game
play
home
我們怎樣才能得到上面列出的所有文本或者一個接一個或所有robotium。
2:有沒有什麼辦法,我們能夠在SD卡(模擬器)來創建一個文件。
請建議一種方法。
您可以使用solo.getCurrentTextViews(查看父),父是列表。
回答第二個問題,試試這個
Context ctx = getInstrumentation().getContext();
AssetManager assetManager = ctx.getAssets();
File a = ctx.getFilesDir();
a.createNewFile();
對於第一個問題,我的解決辦法是:
RelativeLayout rowItem;
for (int i = 0; i < listView.getChildCount(); i++) {
rowItem = (RelativeLayout) listView.getChildAt(i);
TextView tv = (TextView) rowItem
.findViewById(R.id.my_tv);
String text = tv.getText();
}
第二個問題: 當然,你可以
這裏是我的解決辦法如何從ListView項目獲取唯一名稱:
//check if ListView contains elements by getting ListView size
int index = 0;
int elemCount = 0;
ListView listView = (ListView) solo.getCurrentListViews().get(index);
elemCount = listView.getAdapter() != null ? listView.getAdapter().getCount() : 0;
//Creating a Map of existing elements
Map<String, Integer> namesMap = new HashMap<String, Integer>();
//Going through the list of elements and mapping it's names
for (int i = 0; i < elemCount ; i++) {
String name = ((StructureElement) listView.getAdapter().getItem(i)).getName();
namesMap.put(name , i);
}
Log.i("Names and indexes are : " + namesMap);
只要創建一個將要通過它的名字和「反之亦然」,如果你想通過它的索引得到列表項名稱獲取列表項指標的情況下返回namesMap
另一種方法。
隨意重用)
什麼是getCurrentListViews()它似乎並沒有在獨唱存在 – behelit