SortedList.Callback
public abstract class SortedList.Callback<T2> implements Comparator, ListUpdateCallback
SortedList.BatchedCallback |
A callback implementation that can batch notify events dispatched by the SortedList. |
SortedListAdapterCallback |
A |
The class that controls the behavior of the 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.
Summary
Public constructors |
---|
Callback() |
Public methods |
|
---|---|
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 objects represent the same Item or not. |
abstract int |
compare(T2 o1, T2 o2) Similar to |
@Nullable Object |
getChangePayload(T2 item1, T2 item2) When |
abstract void |
onChanged(int position, int count) Called by the SortedList when the item at the given position is updated. |
void |
Called when count} number of items are updated at the given position. |
Inherited methods |
||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||
|
Public constructors
Public methods
areContentsTheSame
public 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. SortedList uses this information to decide whether it should call onChanged
or not.
SortedList uses this method to check equality instead of equals
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.
Parameters | |
---|---|
T2 oldItem |
The previous representation of the object. |
T2 newItem |
The new object that replaces the previous one. |
Returns | |
---|---|
boolean |
True if the contents of the items are the same or false if they are different. |
areItemsTheSame
public abstract boolean areItemsTheSame(T2 item1, T2 item2)
Called by the SortedList to decide whether two objects represent the same Item or not.
For example, if your items have unique ids, this method should check their equality.
Parameters | |
---|---|
T2 item1 |
The first item to check. |
T2 item2 |
The second item to check. |
Returns | |
---|---|
boolean |
True if the two items represent the same object or false if they are different. |
compare
public abstract int compare(T2 o1, T2 o2)
Similar to compare
, should compare two and return how they should be ordered.
Parameters | |
---|---|
T2 o1 |
The first object to compare. |
T2 o2 |
The second object to compare. |
Returns | |
---|---|
int |
a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second. |
getChangePayload
public @Nullable Object getChangePayload(T2 item1, T2 item2)
When areItemsTheSame
returns true
for two items and areContentsTheSame
returns false for them, Callback
calls this method to get a payload about the change.
For example, if you are using Callback
with RecyclerView
, you can return the particular field that changed in the item and your ItemAnimator
can use that information to run the correct animation.
Default implementation returns null
.
Parameters | |
---|---|
T2 item1 |
The first item to check. |
T2 item2 |
The second item to check. |