Cannot change whether this adapter has stable IDs while the adapter has registered observers
You must set the adapter's hasStableIds to true BEFORE you assign the adapter to your recyclerview.
YourAdapter adapter = new YourAdapter();
adapter.setHasStableIds(true);
myRecyclerView.setAdapter(adapter);
as the recyclerView source code:
/**
* Indicates whether each item in the data set can be represented with a unique identifier
* of type {@link java.lang.Long}.
*
* @param hasStableIds Whether items in data set have unique identifiers or not.
* @see #hasStableIds()
* @see #getItemId(int)
*/
public void setHasStableIds(boolean hasStableIds) {
if (hasObservers()) {
throw new IllegalStateException("Cannot change whether this adapter has "
+ "stable IDs while the adapter has registered observers.");
}
mHasStableIds = hasStableIds;
} .
so you can workaround it .
if (!adapter.hasObservers()) {
adapter.setHasStableIds(true)
}