如何使用自定义适配器时,获取该行的ID在onItemClick(ListView中)? [英] How to get the id of the row in onItemClick(ListView) when using a custom Adapter?

查看:375
本文介绍了如何使用自定义适配器时,获取该行的ID在onItemClick(ListView中)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找了一段时间,但我无法找到解决办法。

I was searching for a while but i couldn't find the solution.

情况:

我使用了一个的ListView 和我有一个光标的一个SQLiteDatabase.query的结果。

I'm using a ListView and I have in a Cursor the result of a SQLiteDatabase.query.

  1. 如果我用 SimpleCursorAdapter ,当 你叫 onItemClick(适配器视图<> 家长,查看查看,INT位置, 长ID) ID 返回的是 _id 给定的游标的行

  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

但如果我用一个自定义的适配器的 返回ID就像是一个数组 [0,1,2,3],我怎么能在设定 自定义适配器这个ID?

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?

感谢

推荐答案

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

这篇关于如何使用自定义适配器时,获取该行的ID在onItemClick(ListView中)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆