How do I use test the onClick function of a ListView item using robotium?

78 Views Asked by At

I have a ListView that contains a number of Book objects. If I click on one of the Books in the ListView then it should take me to a new page with the details of the Book (ie. title, author, isbn, etc.) I want to test that this functionality works using robotium but I can't seem to figure out how. I've tried using

solo.clickInList(POSITION_IN_LIST); 

(I only have the one list on this activity) but it does not seem to go to the next activity because my assertion of the current Activity afterward always fails and displays the error message. Any help would be much appreciated.

1

There are 1 best solutions below

0
Bhargav Ghodasara On
listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView parent, View view, int position, long id) {
            String selectedItem = (String) parent.getItemAtPosition(position);
            Toast.makeText(context, selectedItem, Toast.LENGTH_SHORT).show(); 
       }
    });