-
public class FlexibleAdapter.DiffUtilCallback<T extends IFlexible> extends DiffUtil.Callback
Use setItems to set the old and new lists, that are available as:
-
{@code protected ListoldItems;}-{@code protected ListnewItems;}
-
-
Method Summary
Modifier and Type Method Description final List<T>getNewItems()final voidsetItems(List<T> oldItems, List<T> newItems)final intgetOldListSize()final intgetNewListSize()booleanareItemsTheSame(int oldItemPosition, int newItemPosition)Called by the DiffUtil to decide whether two object represent the same item. booleanareContentsTheSame(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. ObjectgetChangePayload(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
-
getNewItems
final List<T> getNewItems()
-
getOldListSize
final int getOldListSize()
-
getNewListSize
final int getNewListSize()
-
areItemsTheSame
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
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 should return 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 the oldItem
-
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
-
-
-
-