【问题标题】:How to get the id of the row in onItemClick(ListView) when using a custom Adapter?使用自定义适配器时如何获取 onItemClick(ListView) 中行的 id?
【发布时间】:2011-01-28 09:35:54
【问题描述】:

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

情况:

我正在使用ListView,我在Cursor 中有一个 SQLiteDatabase.query 的结果。

  1. 如果我使用SimpleCursorAdapter,当 你打电话给onItemClick(AdapterView<?> parent, View view, int position, long id),返回的id就是_id 给定光标所在行的

  2. 但如果我使用自定义适配器 return id 像数组一样工作 [0,1,2,3],如何在 自定义Adapter这个id?

谢谢

【问题讨论】:

    标签: android listview adapter


    【解决方案1】:

    Adapter 有一个可以覆盖的方法,称为getItemId(int pos)。 只需返回给定项目位置所需的任何 id,它就会在项目点击时传递给您。

    【讨论】:

    • 谢谢,看起来是我正在寻找的,正在返回正确的 ID。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-07-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多