BaseAdapter:设置hasStableIds()以虚假的? [英] BaseAdapter: set hasStableIds() to false?

查看:549
本文介绍了BaseAdapter:设置hasStableIds()以虚假的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的ListView 使用 BaseAdapter 的子类。该适配器使用项目指数(位置)的ID,因此,IDS并不稳定(基础数据的操作之一是两个数据项之间的交换)。

我需要在我的适配器覆盖 hasStableIds()返回false

综观 BaseAdapter 在这里建议


  

这是假的是默认的


<一个href=\"http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/widget/BaseAdapter.java\" rel=\"nofollow\">http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/widget/BaseAdapter.java

  //这是必需的?这是不是默认?
@覆盖
公共最后布尔hasStableIds(){
    返回false;
}@覆盖
公众最终长getItemId(INT位置){
    返回的位置;
}


解决方案

没有你不需要重写 hasStableIds()如果你想默认行为,因为它的方法适配器接口的其中的 BaseAdapter 通过的 ListAdapter 和的 SpinnerAdapter ,因此必须提供的一个默认的实现。

然而,你需要重写 getItemId(INT位置),因为它的BaseAdapter类的抽象方法。

I have a ListView that uses a subclass of BaseAdapter. The adapter uses item indices (positions) as ids and thus the ids are not stable (one of the operations on the underlying data is swapping between two data items).

Do I need to override in my adapter hasStableIds() to return false?

Looking at the BaseAdapter here suggest

that false is the default

.

http://www.netmite.com/android/mydroid/frameworks/base/core/java/android/widget/BaseAdapter.java

// Is this required? Isn't this the default?
@Override
public final boolean hasStableIds() {
    return false;
}

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

解决方案

No you do not need to override hasStableIds() if you want the default behavior because its a method of Adapter interface which the BaseAdapter implements through ListAdapter and SpinnerAdapter and therefore has to provide a default implementation of that.

However you do need to override getItemId(int position) because its an abstract method of BaseAdapter class.

这篇关于BaseAdapter:设置hasStableIds()以虚假的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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