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

android android-testing android-robotium

Edit on github
comments powered by Disqus
Click me