I\'m facing some difficults when I try to use the performItemClick funcion of the ListView.
All I want to do is to perform a click programatically i
mList.performItemClick(
mList.getChildAt(mActivePosition),
mActivePosition,
mList.getAdapter().getItemId(mActivePosition));
where mActivePosition
is the position of the child view in List View.
getListView().performItemClick(null, 0, 0)
did the trick for me (for position 0
).
mList.performItemClick(
mList.getAdapter().getView(mActivePosition, null, null),
mActivePosition,
mList.getAdapter().getItemId(mActivePosition));
Where mActivePosition is your click position! All the best! :)
The performClick is probably called before listview was filled, put breakpoint in getView and on performItemClick and check wich is called first
If you are working on a unit test case. Try to use getInstrumentation().waitForIdleSync(), to wait the list be loaded, and extend the ActivityInstrumentationTestCase2 See this answer.
In my case, none of the options solved my problem, so I made an adaptation in my CursorAdapter class. I defined a global variable in the scope, so I just call the class changing this value and check the cursor position by passing the position value
mProductsAdapter.currentPosition = requiredPosition
in my ProductsAdapter builder
var currentPosition = 0
in bindView I do the check
if (cursor.position == currentPosition) {
// perform action
}