BaseAdapter: set hasStableIds() to false?

好久不见. 提交于 2019-12-10 13:57:05

问题


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;
}

回答1:


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.



来源:https://stackoverflow.com/questions/9919822/baseadapter-set-hasstableids-to-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!