Android: onItemClick () position relative to the visible area, not the entire list

I have a question about some behavior in AdapterView.OnItemClickListener, which disappointed me a bit.

I have a ListView supported by a custom CursorAdapter. The cursor is controlled using the LoaderManager. The ListView also has an OnItemClickListener. The data loads correctly, and the ListView is correctly populated - in this case with many elements.

What I find is that the position argument for onItemClick is based on 0 with respect to the items displayed on the screen, and not throughout the list. So, for example, if I scroll down and select the first visible item, I will actually get the first item in the list (which does not appear), and not the one that I selected. When I use the debugger, I see that this position really has a value of 0, although the selected item was much lower in the list.

What is strange is that this worked fine until I started using LoaderManager.

I am using the v4 support library.

If I do something like this:

public void onItemClick( AdapterView<?> parent, View listItem, int position, long id ) {

    Cursor c = myListAdapter.getItem( parent.getFirstVisiblePosition() + position );

    // do stuff

Then I get the data that I actually selected, but somehow I feel this is wrong. I do not need to use getFirstVisiblePosition ().

Any ideas?

thanks

+4
1

, convertView getView() . . , , .

0