public interface DiffCallback<Item>
| Modifier and Type | Method and Description |
|---|---|
boolean |
areContentsTheSame(Item oldItem,
Item newItem)
Called by the DiffUtil when it wants to check whether two items have the same data.
|
boolean |
areItemsTheSame(Item oldItem,
Item newItem)
Called by the DiffUtil to decide whether two object represent the same Item.
|
java.lang.Object |
getChangePayload(Item oldItem,
int oldItemPosition,
Item newItem,
int newItemPosition)
When {#areItemsTheSame(Item, Item)} returns
true for two items and
{#areContentsTheSame(Item, Item)} returns false for them, DiffUtil
calls this method to get a payload about the change. |
boolean areItemsTheSame(Item oldItem, Item newItem)
oldItem - the item in the old listnewItem - the item in the new listboolean areContentsTheSame(Item oldItem, Item newItem)
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(Item, Item) returns
true for these items.oldItem - the item in the old listnewItem - the item in the new list@Nullable java.lang.Object getChangePayload(Item oldItem, int oldItemPosition, Item newItem, int newItemPosition)
true for two items and
{#areContentsTheSame(Item, Item)} 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