public abstract static class SortedList.Callback<T2> extends Object implements Comparator<T2>, ListUpdateCallback
SortedList
.
It defines how items should be sorted and how duplicates should be handled.
SortedList calls the callback methods on this class to notify changes about the underlying data.
Constructor and Description |
---|
Callback() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
areContentsTheSame(T2 oldItem,
T2 newItem)
Called by the SortedList when it wants to check whether two items have the same data
or not.
|
abstract boolean |
areItemsTheSame(T2 item1,
T2 item2)
Called by the SortedList to decide whether two object represent the same Item or not.
|
abstract int |
compare(T2 o1,
T2 o2)
Similar to
Comparator.compare(Object, Object) , should compare two and
return how they should be ordered. |
abstract void |
onChanged(int position,
int count)
Called by the SortedList when the item at the given position is updated.
|
void |
onChanged(int position,
int count,
Object payload)
Called when
count number of items are updated at the given position. |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
comparing, comparing, comparingDouble, comparingInt, comparingLong, equals, naturalOrder, nullsFirst, nullsLast, reversed, reverseOrder, thenComparing, thenComparing, thenComparing, thenComparingDouble, thenComparingInt, thenComparingLong
onInserted, onMoved, onRemoved
public abstract int compare(T2 o1, T2 o2)
Comparator.compare(Object, Object)
, should compare two and
return how they should be ordered.compare
in interface Comparator<T2>
o1
- The first object to compare.o2
- The second object to compare.public abstract void onChanged(int position, int count)
position
- The position of the item which has been updated.count
- The number of items which has changed.public void onChanged(int position, int count, Object payload)
ListUpdateCallback
count
number of items are updated at the given position.onChanged
in interface ListUpdateCallback
position
- The position of the item which has been updated.count
- The number of items which has changed.public abstract boolean areContentsTheSame(T2 oldItem, T2 newItem)
onChanged(int, int)
or not.
SortedList uses this method to check equality instead of Object.equals(Object)
so
that you can change its behavior depending on your UI.
For example, if you are using SortedList with a RecyclerView.Adapter
, you should
return whether the items' visual representations are the same or not.
oldItem
- The previous representation of the object.newItem
- The new object that replaces the previous one.public abstract boolean areItemsTheSame(T2 item1, T2 item2)
For example, if your items have unique ids, this method should check their equality.
item1
- The first item to check.item2
- The second item to check.