user1279214
user1279214

Reputation: 1

Robotium Get Text for the ListView

1: I have a List view as below:

sort
game
play
home

How can we get all the Text of the above List either One by one or all in robotium.

2: Is there any way we are able to create a file in SDcard(Emulator).

Please suggest a way.

Upvotes: 0

Views: 3464

Answers (4)

Pavlik
Pavlik

Reputation: 151

Here is my solution how to get unique names from ListView items:

//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);

Just create additional method which will return namesMap in case you want to get ListItem index by it's name and "vice versa" if you want to get ListItem name by it's index.

Feel free to reuse it)

Upvotes: 0

Tai Tran
Tai Tran

Reputation: 1404

For the first Question, My solution is:

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();

            }

Second Question: Definitely, You can

Upvotes: 1

d3unka
d3unka

Reputation: 74

Answering the second question try this one

Context ctx = getInstrumentation().getContext();
AssetManager assetManager = ctx.getAssets();
File a = ctx.getFilesDir();
a.createNewFile();

Upvotes: 0

Renas
Renas

Reputation: 1919

You can use solo.getCurrentTextViews(View parent) where the parent is the list.

Upvotes: 0

Related Questions