问题
I was searching for a while but i couldn't find the solution.
Situation:
I'm using a ListView and I have in a Cursor the result of a SQLiteDatabase.query.
If I use a
SimpleCursorAdapter, when you callonItemClick(AdapterView<?> parent, View view, int position, long id), theidreturned is the_idof the row of the given Cursorbut if I use a custom Adapter the return id works like an array [0,1,2,3], how can I set in the custom Adapter this id?
Thanks
回答1:
Adapter has a method that you can override, called getItemId(int pos).
Just return whatever id you need for a given item position and it will be passed to you on the item click.
来源:https://stackoverflow.com/questions/4826683/how-to-get-the-id-of-the-row-in-onitemclicklistview-when-using-a-custom-adapte