public static class FlexibleAdapter.DiffUtilCallback<T extends IFlexible>
extends DiffUtil.Callback
setItems(List, List) to set the old and new lists, that are available as:
- protected List<T> oldItems;
- protected List<T> newItems;
| Modifier and Type | Field and Description |
|---|---|
protected java.util.List<T> |
newItems |
protected java.util.List<T> |
oldItems |
| Constructor and Description |
|---|
DiffUtilCallback() |
| Modifier and Type | Method and Description |
|---|---|
boolean |
areContentsTheSame(int oldItemPosition,
int newItemPosition)
Called by the DiffUtil when it wants to check whether two items have the same data.
|
boolean |
areItemsTheSame(int oldItemPosition,
int newItemPosition)
Called by the DiffUtil to decide whether two object represent the same item.
|
java.lang.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. |
java.util.List<T> |
getNewItems() |
int |
getNewListSize() |
int |
getOldListSize() |
void |
setItems(java.util.List<T> oldItems,
java.util.List<T> newItems) |
public final java.util.List<T> getNewItems()
public final int getOldListSize()
public final int getNewListSize()
public 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 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 oldItempublic java.lang.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