Skip to content Skip to sidebar Skip to footer

ListView Row Id And Position Index Confusion

I'm just starting to dive into some basic Android development and have been experimenting with a ListView and integrating it with a SimpleCursorAdapter. I look through a lot of onl

Solution 1:

You can use the position to get a cursor to a particular list entry (and this cursor would be the 'row' in the 'table' corresponding to the row id):

Cursor cursor = (Cursor)parent.getItemAtPosition(pos);
int rowCol = c.getColumnIndex("_id");

Then you should see that cursor.getLong(rowCol) == id


Solution 2:

That is definitely bad practice. I always use the row id to delete, and use the position id to retrieve the cursor's row id. I have the first edition of that book at home, I'm going to take a look at it myself later.


Post a Comment for "ListView Row Id And Position Index Confusion"