Most visited

Recently visited

SortedList.Callback

public static abstract class SortedList.Callback
extends Object implements Comparator<T2>

java.lang.Object
   ↳ android.support.v7.util.SortedList.Callback<T2>
Known Direct Subclasses


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

SortedList.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 object represent the same Item or not.

abstract int compare(T2 o1, T2 o2)

Similar to 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.

abstract void onInserted(int position, int count)

Called by the SortedList when an item is inserted at the given position.

abstract void onMoved(int fromPosition, int toPosition)

Called by the SortedList when an item changes its position in the list.

abstract void onRemoved(int position, int count)

Called by the SortedList when an item is removed from the given position.

Inherited methods

From class java.lang.Object
From interface java.util.Comparator

Public constructors

SortedList.Callback

SortedList.Callback ()

Public methods

areContentsTheSame

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(int, int) or not.

SortedList uses this method to check equality instead of 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.

Parameters
oldItem T2: The previous representation of the object.
newItem T2: 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

boolean areItemsTheSame (T2 item1, 
                T2 item2)

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

For example, if your items have unique ids, this method should check their equality.

Parameters
item1 T2: The first item to check.
item2 T2: The second item to check.
Returns
boolean True if the two items represent the same object or false if they are different.

compare

int compare (T2 o1, 
                T2 o2)

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

Parameters
o1 T2: The first object to compare.
o2 T2: 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.

onChanged

void onChanged (int position, 
                int count)

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

Parameters
position int: The position of the item which has been updated.
count int: The number of items which has changed.

onInserted

void onInserted (int position, 
                int count)

Called by the SortedList when an item is inserted at the given position.

Parameters
position int: The position of the new item.
count int: The number of items that have been added.

onMoved

void onMoved (int fromPosition, 
                int toPosition)

Called by the SortedList when an item changes its position in the list.

Parameters
fromPosition int: The previous position of the item before the move.
toPosition int: The new position of the item.

onRemoved

void onRemoved (int position, 
                int count)

Called by the SortedList when an item is removed from the given position.

Parameters
position int: The position of the item which has been removed.
count int: The number of items which have been removed.

Hooray!