Reputation: 824
I have an ExpandableListView implementation in my application and I am writing unit tests for it. I'm wondering how I can programmatically perform a click on the child view of an expandable header?
This is NOT a question about how to attach onChildClickListener() to the view. I've found many questions regarding that topic, but I already have that implemented and need to test the functionality of that code when the child view is clicked. I know that I can use the performClick() method to click on the header view to expand/collapse the contents, but I need to perform a click on the sublist of a header.
Upvotes: 2
Views: 1453
Reputation: 435
You can try with:
listView.setSelection(position);
but you have to consider this:
If in touch mode, the item will not be selected but it will still be positioned appropriately. If the specified selection position is less than 0, then the item at position 0 will be selected.
For more information you can visit the doc page.
I hope it helps.
Edit
As @RyanM appointed, setSelection just change the selection, but it doesn't perform the "click" action. You can perform the action through the function:
listView.performItemClick(goalListView, itemPosition, itemId);
You can find this function in the class AdapterView.
Sorry for the previous mistake to your answer.
Upvotes: 2