Alex Rivera | Logout

Android - How to tap ListView item programmatically

Asked 2012-03-22T10:12:41.190
31

How to call ItemClickListener programmatically? listView.performItemClick() does not work. Is that possible?

Edit
Report

2 Answers

70
mList.performItemClick(
    mList.getAdapter().getView(mActivePosition, null, null),
    mActivePosition,
    mList.getAdapter().getItemId(mActivePosition));

Where mActivePosition is your click position!

answered 2013-04-29T12:05:45.860
2

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.

answered 2012-03-22T10:27:07.097

Your Answer