public abstract class

SortedList.Callback<T2>

extends java.lang.Object

implements java.util.Comparator<java.lang.Object>, ListUpdateCallback

 java.lang.Object

↳androidx.recyclerview.widget.SortedList.Callback<T2>

Subclasses:

SortedListAdapterCallback<T2>, SortedList.BatchedCallback<T2>

Overview

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

Constructors
publicCallback()

Methods
public abstract booleanareContentsTheSame(java.lang.Object oldItem, java.lang.Object newItem)

Called by the SortedList when it wants to check whether two items have the same data or not.

public abstract booleanareItemsTheSame(java.lang.Object item1, java.lang.Object item2)

Called by the SortedList to decide whether two objects represent the same Item or not.

public abstract intcompare(java.lang.Object o1, java.lang.Object o2)

Similar to compare, should compare two and return how they should be ordered.

public java.lang.ObjectgetChangePayload(java.lang.Object item1, java.lang.Object item2)

When SortedList.Callback returns true for two items and SortedList.Callback returns false for them, SortedList.Callback calls this method to get a payload about the change.

public abstract voidonChanged(int position, int count)

Called by the SortedList when the item at the given position is updated.

public voidonChanged(int position, int count, java.lang.Object payload)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Callback()

Methods

public abstract int compare(java.lang.Object o1, java.lang.Object o2)

Similar to compare, should compare two and return how they should be ordered.

Parameters:

o1: The first object to compare.
o2: The second object to compare.

Returns:

a negative integer, zero, or a positive integer as the first argument is less than, equal to, or greater than the second.

public abstract void onChanged(int position, int count)

Called by the SortedList when the item at the given position is updated.

Parameters:

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, java.lang.Object payload)

public abstract boolean areContentsTheSame(java.lang.Object oldItem, java.lang.Object 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 SortedList.Callback.onChanged(int, int) 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:

oldItem: The previous representation of the object.
newItem: The new object that replaces the previous one.

Returns:

True if the contents of the items are the same or false if they are different.

public abstract boolean areItemsTheSame(java.lang.Object item1, java.lang.Object 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:

item1: The first item to check.
item2: The second item to check.

Returns:

True if the two items represent the same object or false if they are different.

public java.lang.Object getChangePayload(java.lang.Object item1, java.lang.Object item2)

When SortedList.Callback returns true for two items and SortedList.Callback returns false for them, SortedList.Callback calls this method to get a payload about the change.

For example, if you are using SortedList.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:

item1: The first item to check.
item2: The second item to check.

Returns:

A payload object that represents the changes between the two items.