How to override getItemId (int pos) method from CursorAdapter?

I get this question because of a different answer here, but did not explain how to do what I ask. How do I get the row id in onItemClick (ListView) when using a custom adapter?

The answer that was accepted in this question is what I need, since I am also creating my own adapter (CursorAdapter), so I will have the same problem. The problem is that I have no idea how to do this. I am looking at the Doc, and not sure how to access the _id column from the cursor. Since Doc has no constant that we can get from this information, I'm stuck. Any help on this would be greatly appreciated.

EDIT: It wasn’t clear to me what my question was, but just to clarify how the name is, how can I override the getItemId () method in the custom CursorAdapter class that I created?

+5
source share
2 answers

Assuming you don't have a cursor as a member of your adapter:

@Override
public long getItemId(int position) {
    Cursor cursor = getCursor();
    cursor.moveToPosition(position);
    return cursor.getLong(mCursor.getColumnIndex("_id"));
}
+9
source

I do not think this does not answer the question posed, but Sam took care of it. I thought I would post this because there seems to be some confusion regarding the OPs.

The following is a method onListItemClickfrom an action that contains a list created using a custom cursor adapter:

@Override
public void onListItemClick(ListView l, View v, int position, long id) {
    // Your code here
}

long id - , ( ). getItemId.

getItemId ( ), - , . , .

, , , .. ...

+4

All Articles