使用自定义适配器时如何获取 onItemClick(ListView) 中行的 id?
我搜索了一段时间但找不到解决方案。
情况:
我正在使用 ListView
并且在 Cursor
中有 SQLiteDatabase.query 的结果。
如果我使用
SimpleCursorAdapter
,当 您调用onItemClick(AdapterView; 父级、视图视图、int 位置、 long id)
,返回的id
为_id
给定 Cursor 的行的行,但是如果我使用自定义适配器 返回 id 像数组一样工作 [0,1,2,3],如何设置 自定义适配器这个 id?
谢谢
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<?>
, the
parent, View view, int position,
long id)id
returned is the_id
of 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
适配器有一个可以重写的方法,称为
getItemId(int pos)
。只需返回给定项目位置所需的任何 id,它就会在项目单击时传递给您。
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.