How to call ItemClickListener
programmatically? listView.performItemClick()
does not work. Is that possible?
If you need it for testing purposes, then you can use Robotium ( http://code.google.com/p/robotium/ ).
You could also achieve what you want by calling the onClick
method of the ClickController
with the correct parameters.
The answer is
listView1.performItemClick(listView1, 3, listView1.getItemIdAtPosition(3));
from the link
http://mantascode.com/?p=486
mList.performItemClick(
mList.getAdapter().getView(mActivePosition, null, null),
mActivePosition,
mList.getAdapter().getItemId(mActivePosition));
Where mActivePosition is your click position!
You can set up an onItemClick
listener for your list view via
listView.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//here you do something
}
});
Assign tag in the adapter to each View
, and findviewByTag()
this worked for me:
listView.performItemClick(listView.findViewWithTag(listView.getAdapter().getItem(selectedIndex)), selectedIndex, listView.getAdapter().getItemId(selectedIndex));
Also refer this answer.
If you want to click/tap/select 3rd list item then.
listView.performItemClick(listView.getAdapter().getView(3, null, null), 3, listView.getItemIdAtPosition(3));
This worked perfectly for me.