# DiffUtil.Callback

added in[version 25.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.Callback#pubctors)\|[Methods](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#inhmethods)\|[\[Expand All\]](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#)  

# DiffUtil.Callback

| 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.Callback
`  
`

extends Object


``


`

|---|-------------------------------------------|
| java.lang.Object                             ||
| ↳ | android.support.v7.util.DiffUtil.Callback |

<br />

*** ** * ** ***

A Callback class used by DiffUtil while calculating the diff between two lists.

## Summary

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

|                                                                                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                                                                                  ||
|---------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract boolean` | ` `[areContentsTheSame](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#areContentsTheSame(int, int))`(int oldItemPosition, int newItemPosition) ` Called by the DiffUtil when it wants to check whether two items have the same data.                                                                                                                                                                                                                                                                                                                       |
| ` abstract boolean` | ` `[areItemsTheSame](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#areItemsTheSame(int, int))`(int oldItemPosition, int newItemPosition) ` Called by the DiffUtil to decide whether two object represent the same Item.                                                                                                                                                                                                                                                                                                                                    |
| ` Object`           | ` `[getChangePayload](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#getChangePayload(int, int))`(int oldItemPosition, int newItemPosition) ` When[areItemsTheSame(int, int)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#areItemsTheSame(int, int))returns`true`for two items and[areContentsTheSame(int, int)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#areContentsTheSame(int, int))returns false for them, DiffUtil calls this method to get a payload about the change. |
| ` abstract int`     | ` `[getNewListSize](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#getNewListSize())`() ` Returns the size of the new list.                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ` abstract int`     | ` `[getOldListSize](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#getOldListSize())`() ` Returns the size of the old list.                                                                                                                                                                                                                                                                                                                                                                                                                                 |

| ### Inherited methods |
|-----------------------|---|
| [![](https://developer.android.com/static/assets/images/styles/disclosure_down.png)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#)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.Callback

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

```
DiffUtil.Callback ()
```

<br />

<br />

## Public methods

### areContentsTheSame

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

```
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(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(int, int)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#areItemsTheSame(int, int))returns`true`for these items.

<br />

|                                              Parameters                                              ||
|-------------------|-----------------------------------------------------------------------------------|
| `oldItemPosition` | `int`: The position of the item in the old list <br />                            |
| `newItemPosition` | `int`: The position of the item in the new list which replaces the oldItem <br /> |

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

### areItemsTheSame

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

```
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.

<br />

|                                Parameters                                 ||
|-------------------|--------------------------------------------------------|
| `oldItemPosition` | `int`: The position of the item in the old list <br /> |
| `newItemPosition` | `int`: The position of 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 /> |

### getChangePayload

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

```
Object getChangePayload (int oldItemPosition, 
                int newItemPosition)
```

When[areItemsTheSame(int, int)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#areItemsTheSame(int, int))returns`true`for two items and[areContentsTheSame(int, int)](https://developer.android.com/reference/android/support/v7/util/DiffUtil.Callback#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](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                                 ||
|-------------------|--------------------------------------------------------|
| `oldItemPosition` | `int`: The position of the item in the old list <br /> |
| `newItemPosition` | `int`: The position of the item in the new list <br /> |

|                                       Returns                                       ||
|----------|---------------------------------------------------------------------------|
| `Object` | A payload object that represents the change between the two items. <br /> |

### getNewListSize

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

```
int getNewListSize ()
```

Returns the size of the new list.

<br />

|                 Returns                 ||
|-------|----------------------------------|
| `int` | The size of the new list. <br /> |

### getOldListSize

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

```
int getOldListSize ()
```

Returns the size of the old list.

<br />

|                 Returns                 ||
|-------|----------------------------------|
| `int` | The size of the old list. <br /> |

-

  ## 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)