-
public abstract class DiffUtil.Callback
A Callback class used by DiffUtil while calculating the diff between two lists.
-
-
Method Summary
Modifier and Type Method Description abstract int
getOldListSize()
Returns the size of the old list. abstract int
getNewListSize()
Returns the size of the new list. abstract boolean
areItemsTheSame(int oldItemPosition, int newItemPosition)
Called by the DiffUtil to decide whether two object represent the same Item. abstract boolean
areContentsTheSame(int oldItemPosition, int newItemPosition)
Called by the DiffUtil when it wants to check whether two items have the same data.DiffUtil uses this information to detect if the contents of an item has changed. Object
getChangePayload(int oldItemPosition, int newItemPosition)
When areItemsTheSame returns {@code true}
for two items and areContentsTheSame returns false for them, DiffUtilcalls this method to get a payload about the change.-
-
Method Detail
-
getOldListSize
abstract int getOldListSize()
Returns the size of the old list.
-
getNewListSize
abstract int getNewListSize()
Returns the size of the new list.
-
areItemsTheSame
abstract boolean areItemsTheSame(int oldItemPosition, int newItemPosition)
Called by the DiffUtil to decide whether two object represent the same Item.
For example, if your items have unique ids, this method should check their id equality.
- Parameters:
oldItemPosition
- The position of the item in the old listnewItemPosition
- The position of the item in the new list
-
areContentsTheSame
abstract boolean areContentsTheSame(int oldItemPosition, int newItemPosition)
Called by the DiffUtil when it wants to check whether two items have the same data.DiffUtil uses this information to detect if the contents of an item has changed.
DiffUtil 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 DiffUtil with a RecyclerView.Adapter, you shouldreturn whether the items' visual representations are the same.
This method is called only if areItemsTheSame returns
{@code true}
for these items.- Parameters:
oldItemPosition
- The position of the item in the old listnewItemPosition
- The position of the item in the new list which replaces theoldItem
-
getChangePayload
@Nullable() Object getChangePayload(int oldItemPosition, int newItemPosition)
When areItemsTheSame returns
{@code true}
for two items and areContentsTheSame returns false for them, DiffUtilcalls this method to get a payload about the change.For example, if you are using DiffUtil with RecyclerView, you can return theparticular field that changed in the item and your ItemAnimator can use thatinformation to run the correct animation.
Default implementation returns
{@code null}
.- Parameters:
oldItemPosition
- The position of the item in the old listnewItemPosition
- The position of the item in the new list
-
-
-
-