Android - ListView - performItemClick Android - ListView - performItemClick android android

Android - ListView - performItemClick


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

Where mActivePosition is your click position! All the best! :)


This worked for me.

listView.performItemClick(    listView.getAdapter().getView(position, null, null), position, position);

use the adapter to get the view for the position of the item. The other 2 parameters I didn't want so I left them null. Leaving convertView null causes the adapter to render a new view. It's a performance issue but since this is only happening once in a while it wont have much effect. I don't need to specify the parent for anything because I'm not using it.

position is just the spot where your item is located.Additionally these 2 lines of code before your performItemClick create the illusion of having the list item selected. They also ensure the appropriate item is on the screen.

listView.requestFocusFromTouch();listView.setSelection(position);


This works best for me. Run this on the main thread.

new Handler().post(new Runnable() {    @Override    public void run() {        mList.performItemClick(                mList.getChildAt(mActivePosition),                mActivePosition,                mList.getAdapter().getItemId(mActivePosition));    }});

This is similar to Arun Jose's answer, but it will queue a message to the main thread to give the ListView some time to initiate.