1: 以下のようなリスト ビューがあります。
sort
game
play
home
上記のリストのすべてのテキストを 1 つずつ、またはすべて robotium で取得するにはどうすればよいでしょうか。
2: SDcard(エミュレータ)でファイルを作成する方法はありますか?
方法を提案してください。
最初の質問について、私の解決策は次のとおりです。
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();
}
2 番目の質問: もちろん、できます
親がリストの場合、solo.getCurrentTextViews(View parent) を使用できます。
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);
ListItem インデックスをその名前で取得したい場合に返される追加のメソッドを作成し、namesMap
そのインデックスで ListItem 名を取得したい場合は「その逆」を作成します。
ご自由に再利用してください)
2番目の質問に答えて、これを試してください
Context ctx = getInstrumentation().getContext();
AssetManager assetManager = ctx.getAssets();
File a = ctx.getFilesDir();
a.createNewFile();