Package 

Class FlexibleAdapter.DiffUtilCallback

    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected List<T> newItems
    • Method Summary

      Modifier and Type Method Description
      final List<T> getNewItems()
      final void setItems(List<T> oldItems, List<T> newItems)
      final int getOldListSize()
      final int getNewListSize()
      boolean areItemsTheSame(int oldItemPosition, int newItemPosition) Called by the DiffUtil to decide whether two object represent the same item.
      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.
      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.
      • Methods inherited from class androidx.recyclerview.widget.DiffUtil.Callback

        areContentsTheSame, areItemsTheSame, getChangePayload, getNewListSize, getOldListSize
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • 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 list
        newItemPosition - 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 list
        newItemPosition - 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 list
        newItemPosition - The position of the item in the new list