什么是项目-ID的Andr​​oid中的ListView适配器的目的是什么? [英] What's the purpose of item-id's in Android ListView Adapter?

查看:109
本文介绍了什么是项目-ID的Andr​​oid中的ListView适配器的目的是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

(并不特指的ListView,但适配器)。

(Not specific to ListView, but to Adapter).

我一直在实施,当我继承BaseAdapter:

I keep implementing this when I subclass BaseAdapter:

    @Override
    public long getItemId(int position) {
        return position; 
    }

由于要实现这一点。我看不出有什么用呢,我需要的getItem(位置),不适getItemId(位置)。

Because have to implement that. I don't see any use of it, I need getItem(position) only, not getItemId(position).

我不知道这有什么意义(至Android SDK或者别的什么)?

I wonder if it has any significance (to Android SDK or something else)?

推荐答案

有可能是很多原因有稳定项ID。一个默认的实现不能给​​予,因为它取决于对象的类型被存储在适配器

There are probably many reasons to have stable item IDs. A default implementation cannot be given since it depends on the type of Object being stored in the Adapter.

Android有一个检查,以确保该项目的ID仅用于他们马厩的时候,也就是子类已妥善覆盖 getItemId ; 必须重写以返回true BaseAdapter.hasStableIds

Android has a check to make sure that item IDs are used only when they are stabled, i.e. the subclass has properly overridden getItemId; BaseAdapter.hasStableIds must be overriden to return true.

几个原因我所遇到的:

getCheckedItemIds 方法结果是只有有效的,如果选择模式没有被设定为CHOICE_MODE_NONE且适配器具有稳定的ID。

回复的因为必须执行该的:你不知道的必须如果您不使用的功能,就没有必要。但是,如果你做什么,不要忘了覆盖布尔hasStableIds()

Reply to "Because have to implement that": you don't have to If you don't use the features, there's no need. But if you do, don't forget to override boolean hasStableIds() as well.

这篇关于什么是项目-ID的Andr​​oid中的ListView适配器的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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