使用自定义适配器时如何获取 onItemClick(ListView) 中行的 id?

发布于 2024-10-14 17:43:43 字数 405 浏览 4 评论 0原文

我搜索了一段时间但找不到解决方案。

情况:

我正在使用 ListView 并且在 Cursor 中有 SQLiteDatabase.query 的结果。

  1. 如果我使用SimpleCursorAdapter,当 您调用 onItemClick(AdapterView; 父级、视图视图、int 位置、 long id),返回的id_id 给定 Cursor 的行

  2. 的行,但是如果我使用自定义适配器 返回 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.

  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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

格子衫的從容 2024-10-21 17:43:43

适配器有一个可以重写的方法,称为 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文