I have some problems understanding RecyclerView
s SortedList
.
Lets say I have a very simple class only having a very simple class holding data:<
SortedList does not keep any mapping by ids (because there are no ids in the API). So when the sorting criteria changes (a to b in your case), SortedList cannot find the existing element.
You can keep the id mapping yourself, then have your add method as follows:
void add(Item t) {
Item existing = idMap.get(t.id);
if (existing == null) {
sortedList.add(t);
} else {
sortedList.updateItemAt(sortedList.indexOf(existing), t);
}
idMap.put(t.id, t);
}
You'll also need to implement a remove method to remove the item from the idMap.