Tagged: android-robotium

Android testing: Click an item in a ListView

There are two ways to do this. The Andrioid instrumentation and the Robotium way.

final ListView listLiew = (ListView) activity.findViewById(R.id.your_list_view);
runTestOnUiThread(new Runnable() {
    public void run() {
       listLiew.performItemClick(listLiew, POSTITION_IN_LIST, listLiew.getItemIdAtPosition(POSTITION_IN_LIST));

You get a reference to the list view, and call performItemClick.

Robotium is simpler, using just


This means you must know what number the list is in your page – which you may not be able to be sure of easily.

Obviously if you just have one list, then this method works the best.

The source of Robotium’s method is at: https://github.com/jayway/robotium/blob/master/robotium-solo/src/main/java/com/jayway/android/robotium/solo/Clicker.java

android android-testing android-robotium

Page 1 of 1