# DiffUtil.ItemCallback

added in [version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)   
belongs to Maven artifact com.android.support:recyclerview-v7:28.0.0-alpha1  
Summary: [Ctors](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#pubctors) \| [Methods](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#inhmethods) \| [\[Expand All\]](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#)  

# DiffUtil.ItemCallback

| This package is part of the Android [support library](https://developer.android.com/topic/libraries/support-library) which is no longer maintained. The support library has been superseded by [AndroidX](https://developer.android.com/jetpack/androidx) which is part of [Jetpack](https://developer.android.com/jetpack). We recommend using the AndroidX libraries in all new projects. You should also consider [migrating](https://developer.android.com/jetpack/androidx/migrate) existing projects to AndroidX. To find the AndroidX class that maps to this deprecated class, see the AndroidX support library [class
| mappings](https://developer.android.com/jetpack/androidx/migrate/class-mappings).


`
public
static

abstract
class
DiffUtil.ItemCallback
`


`

extends Object


`

`


`

|---|----------------------------------------------------|
| java.lang.Object                                      ||
| ↳ | android.support.v7.util.DiffUtil.ItemCallback\<T\> |

<br />

*** ** * ** ***

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


[DiffUtil.Callback](https://developer.android.com/reference/android/support/v7/util/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.

## Summary

|                                                              ### Public constructors                                                              ||
|------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[DiffUtil.ItemCallback](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#DiffUtil.ItemCallback())`() ` |

|                                                                                                                                                                                                                                                                                    ### Public methods                                                                                                                                                                                                                                                                                    ||
|---------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract boolean` | ` `[areContentsTheSame](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#areContentsTheSame(T, T))`(T oldItem, T newItem) ` Called to check whether two items have the same data.                                                                                                                                                                                                                                                                                                                                              |
| ` abstract boolean` | ` `[areItemsTheSame](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#areItemsTheSame(T, T))`(T oldItem, T newItem) ` Called to check whether two objects represent the same item.                                                                                                                                                                                                                                                                                                                                             |
| ` Object`           | ` `[getChangePayload](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#getChangePayload(T, T))`(T oldItem, T newItem) ` When [areItemsTheSame(T, T)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#areItemsTheSame(T, T)) returns `true` for two items and [areContentsTheSame(T, T)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#areContentsTheSame(T, T)) returns false for them, this method is called to get a payload about the change. |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#)From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object`         | ` clone() `                   | | ` boolean`        | ` equals(Object arg0) `       | | ` void`           | ` finalize() `                | | ` final Class<?>` | ` getClass() `                | | ` int`            | ` hashCode() `                | | ` final void`     | ` notify() `                  | | ` final void`     | ` notifyAll() `               | | ` String`         | ` toString() `                | | ` final void`     | ` wait(long arg0, int arg1) ` | | ` final void`     | ` wait(long arg0) `           | | ` final void`     | ` wait() `                    | ||

## Public constructors

### DiffUtil.ItemCallback

added in [version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
DiffUtil.ItemCallback ()
```

<br />

<br />

## Public methods

### areContentsTheSame

added in [version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
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 [equals(Object)](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)) so that you can
change its behavior depending on your UI.


For example, if you are using DiffUtil with a
[RecyclerView.Adapter](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.Adapter), you should
return whether the items' visual representations are the same.


This method is called only if [areItemsTheSame(T, T)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#areItemsTheSame(T, T)) returns `true` for
these items.


Note: Two `null` items are assumed to represent the same contents. This callback
will not be invoked for this case.

<br />

|                    Parameters                    ||
|-----------|---------------------------------------|
| `oldItem` | `T`: The item in the old list. <br /> |
| `newItem` | `T`: The item in the new list. <br /> |

|                                             Returns                                              ||
|-----------|---------------------------------------------------------------------------------------|
| `boolean` | True if the contents of the items are the same or false if they are different. <br /> |

**See also:**

- [areContentsTheSame(int, int)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#areContentsTheSame(int, int))  

### areItemsTheSame

added in [version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
boolean areItemsTheSame (T oldItem, 
                T newItem)
```

Called to check whether two objects represent the same item.


For example, if your items have unique ids, this method should check their id equality.


Note: `null` items in the list are assumed to be the same as another `null`
item and are assumed to not be the same as a non-`null` item. This callback will
not be invoked for either of those cases.

<br />

|                    Parameters                    ||
|-----------|---------------------------------------|
| `oldItem` | `T`: The item in the old list. <br /> |
| `newItem` | `T`: The item in the new list. <br /> |

|                                              Returns                                              ||
|-----------|----------------------------------------------------------------------------------------|
| `boolean` | True if the two items represent the same object or false if they are different. <br /> |

**See also:**

- [areItemsTheSame(int, int)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#areItemsTheSame(int, int))  

### getChangePayload

added in [version 27.1.0](https://developer.android.com/topic/libraries/support-library/revisions)  

```
Object getChangePayload (T oldItem, 
                T newItem)
```

When [areItemsTheSame(T, T)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#areItemsTheSame(T, T)) returns `true` for two items and
[areContentsTheSame(T, T)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback#areContentsTheSame(T, T)) returns false for them, this method is called to
get a payload about the change.


For example, if you are using DiffUtil with [RecyclerView](https://developer.android.com/reference/android/support/v7/widget/RecyclerView), you can return the
particular field that changed in the item and your
[ItemAnimator](https://developer.android.com/reference/android/support/v7/widget/RecyclerView.ItemAnimator) can use that
information to run the correct animation.


Default implementation returns `null`.

<br />

|      Parameters       ||
|-----------|------------|
| `oldItem` | `T` <br /> |
| `newItem` | `T` <br /> |

|     Returns      ||
|----------|--------|
| `Object` | <br /> |

**See also:**

- [getChangePayload(int, int)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#getChangePayload(int, int))  
-

  ## Interfaces

  - [ListUpdateCallback](https://developer.android.com/reference/android/support/v7/util/ListUpdateCallback)
-

  ## Classes

  - [AdapterListUpdateCallback](https://developer.android.com/reference/android/support/v7/util/AdapterListUpdateCallback)
  - [AsyncListUtil](https://developer.android.com/reference/android/support/v7/util/AsyncListUtil)
  - [AsyncListUtil.DataCallback](https://developer.android.com/reference/android/support/v7/util/AsyncListUtil.DataCallback)
  - [AsyncListUtil.ViewCallback](https://developer.android.com/reference/android/support/v7/util/AsyncListUtil.ViewCallback)
  - [BatchingListUpdateCallback](https://developer.android.com/reference/android/support/v7/util/BatchingListUpdateCallback)
  - [DiffUtil](https://developer.android.com/reference/android/support/v7/util/DiffUtil)
  - [DiffUtil.Callback](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback)
  - [DiffUtil.DiffResult](https://developer.android.com/reference/android/support/v7/util/DiffUtil.DiffResult)
  - [DiffUtil.ItemCallback](https://developer.android.com/reference/android/support/v7/util/DiffUtil.ItemCallback)
  - [SortedList](https://developer.android.com/reference/android/support/v7/util/SortedList)
  - [SortedList.BatchedCallback](https://developer.android.com/reference/android/support/v7/util/SortedList.BatchedCallback)
  - [SortedList.Callback](https://developer.android.com/reference/android/support/v7/util/SortedList.Callback)