How to get the id of the row in onItemClick(ListView) when using a custom Adapter?

泄露秘密 提交于 2019-12-09 19:32:59

问题


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.

  1. If I use a SimpleCursorAdapter, when you call onItemClick(AdapterView<?> parent, View view, int position, long id), the id returned is the _id of the row of the given Cursor

  2. but 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!