public static abstract class DiffUtil.ItemCallback
extends Object

   ↳ androidx.recyclerview.widget.DiffUtil.ItemCallback<T>

Callback for calculating the diff between two non-null items in a list.

DiffUtil.Callback serves two roles - list indexing, and item diffing. ItemCallback handles just the second of these, which allows separation of code that indexes into an array or List from the presentation-layer and content specific diffing code.


Public constructors


Public methods

abstract boolean areContentsTheSame(T oldItem, T newItem)

Called to check whether two items have the same data.

abstract boolean areItemsTheSame(T oldItem, T newItem)

Called to check whether two objects represent the same item.

Object getChangePayload(T oldItem, T newItem)

When areItemsTheSame(T, T) returns true for two items and areContentsTheSame(T, T) returns false for them, this method is called to get a payload about the change.

Inherited methods

Public constructors


public ItemCallback ()

Public methods


public abstract boolean areContentsTheSame (T oldItem, 
                T newItem)

Called to check whether two items have the same data.

This information is used to detect if the contents of an item have changed.

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(T, T)