0

1: 以下のようなリスト ビューがあります。

sort
game
play
home

上記のリストのすべてのテキストを 1 つずつ、またはすべて robotium で取得するにはどうすればよいでしょうか。

2: SDcard(エミュレータ)でファイルを作成する方法はありますか?

方法を提案してください。

4

4 に答える 4

1

最初の質問について、私の解決策は次のとおりです。

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 番目の質問: もちろん、できます

于 2012-05-26T00:08:28.043 に答える
0

親がリストの場合、solo.getCurrentTextViews(View parent) を使用できます。

于 2012-05-14T15:44:18.943 に答える
0

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 名を取得したい場合は「その逆」を作成します。

ご自由に再利用してください)

于 2014-06-30T10:15:02.353 に答える
0

2番目の質問に答えて、これを試してください

Context ctx = getInstrumentation().getContext();
AssetManager assetManager = ctx.getAssets();
File a = ctx.getFilesDir();
a.createNewFile();
于 2012-05-25T22:50:33.077 に答える