开发者

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

开发者 https://www.devze.com 2023-02-07 00:58 出处:网络
I was searching for a while but i couldn\'tfind the solution. Situation: I\'m using a ListView and I have in a Cursor the result of a SQLiteDatabase.query.

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 i开发者_运维技巧d?

Thanks


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号