Constructor and Description |
---|
Callback() |
Modifier and Type | Method and Description |
---|---|
abstract boolean |
areContentsTheSame(int oldItemPosition,
int newItemPosition)
Called by the DiffUtil when it wants to check whether two items have the same data.
|
abstract boolean |
areItemsTheSame(int oldItemPosition,
int newItemPosition)
Called by the DiffUtil to decide whether two object represent the same Item.
|
Object |
getChangePayload(int oldItemPosition,
int newItemPosition)
When
areItemsTheSame(int, int) returns true for two items and
areContentsTheSame(int, int) returns false for them, DiffUtil
calls this method to get a payload about the change. |
abstract int |
getNewListSize()
Returns the size of the new list.
|
abstract int |
getOldListSize()
Returns the size of the old list.
|
public abstract int getOldListSize()
public abstract int getNewListSize()
public abstract boolean areItemsTheSame(int oldItemPosition, int newItemPosition)
For example, if your items have unique ids, this method should check their id equality.
oldItemPosition
- The position of the item in the old listnewItemPosition
- The position of the item in the new listpublic abstract boolean areContentsTheSame(int oldItemPosition, int newItemPosition)
DiffUtil 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 DiffUtil with a
RecyclerView.Adapter
, you should
return whether the items' visual representations are the same.
This method is called only if areItemsTheSame(int, int)
returns
true
for these items.
oldItemPosition
- The position of the item in the old listnewItemPosition
- The position of the item in the new list which replaces the
oldItem@Nullable public Object getChangePayload(int oldItemPosition, int newItemPosition)
areItemsTheSame(int, int)
returns true
for two items and
areContentsTheSame(int, int)
returns false for them, DiffUtil
calls this method to get a payload about the change.
For example, if you are using DiffUtil 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
.
oldItemPosition
- The position of the item in the old listnewItemPosition
- The position of the item in the new list