Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

BaseAdapter: set hasStableIds() to false?

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;
}
like image 669
user1139880 Avatar asked Oct 09 '22 06:10

user1139880


1 Answers

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.

like image 141
vKashyap Avatar answered Oct 12 '22 11:10

vKashyap