如何重写getItemId(INT POS)从CursorAdapter的方法? [英] How to override the getItemId(int pos) method from CursorAdapter?

查看:215
本文介绍了如何重写getItemId(INT POS)从CursorAdapter的方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到这个问题由于对这里的另一个答案,但并没有解释如何做什么,我问 <一href="http://stackoverflow.com/questions/4826683/how-to-get-the-id-of-the-row-in-onitemclicklistview-when-using-a-custom-adapte">How获得该行的ID在onItemClick(ListView中)使用自定义适配器时?

I am getting this question due to another answer on here, but didn't explain how to do what I am asking How to get the id of the row in onItemClick(ListView) when using a custom Adapter?

这是接受了这个问题的答案是什么,我需要的,因为我也正在自己的自定义适配器(CursorAdapter的),所以我也会有同样的问题。问题是我不知道如何来实现这一目标。我在看的医生,而我不知道如何从一个游标访问_id列。由于文档没有它,我们可以得到的信息,从我坚持不变。任何帮助计算出来会更AP preciated。

The answer which was accepted in that question is what I need since I am also making my own custom adapter (CursorAdapter), hence I will have the same problem. The problem is I have no idea how to accomplish that. I am looking at the Doc, and am not sure how to access the _id column from a cursor. Since the Doc doesn't have the constant which we can get that info from I'm stuck. Any help figuring it out would be much appreciated.

编辑:我不清楚​​什么我的问题,但我只想澄清,如标题,我怎么可以覆盖我创建的CursorAdapter的自定义类的getItemId()方法

I was not clear on what my question was, but just to clarify, like the title, how can I override the getItemId() method in the CursorAdapter custom class I created?

推荐答案

假设你没有光标作为您的适配器的成员:

Assuming you don't have the Cursor as a member of your Adapter:

@Override
public long getItemId(int position) {
    Cursor cursor = getCursor();
    cursor.moveToPosition(position);
    return cursor.getLong(mCursor.getColumnIndex("_id"));
}

这篇关于如何重写getItemId(INT POS)从CursorAdapter的方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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