public interface ParameterizedDiffCallback<E>
| Modifier and Type | Method and Description |
|---|---|
boolean |
areContentsTheSame(E oldItem,
E newItem)
Called by the DiffUtil when it wants to check whether two items have the same data.
|
boolean |
areItemsTheSame(E oldItem,
E newItem)
Called by the DiffUtil to decide whether two object represent the same Item.
|
Object |
getChangePayload(E oldItem,
E newItem)
When
#areItemsTheSame(E, E) returns true for two items and
#areContentsTheSame(E, E) returns false for them, DiffUtil
calls this method to get a payload about the change. |
boolean areItemsTheSame(@NonNull E oldItem, @NonNull E newItem)
For example, if your items have unique ids, this method should check their id equality.
oldItem - The item in the old list.newItem - The item in the new list associated with the same position as an old item.boolean areContentsTheSame(@NonNull E oldItem, @NonNull E newItem)
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(E, E) returns
true for these items.
oldItem - The item in the old list.newItem - The item in the new list associated with the same position as an old item.@Nullable Object getChangePayload(@NonNull E oldItem, @NonNull E newItem)
#areItemsTheSame(E, E) returns true for two items and
#areContentsTheSame(E, E) 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.
oldItem - The item in the old listnewItem - The item in the new list