# DiffCallback

# DiffCallback

Artifact:[androidx.leanback:leanback](https://developer.android.com/jetpack/androidx/releases/leanback)  
[View Source](https://cs.android.com/search?q=file:androidx/leanback/widget/DiffCallback.java+class:androidx.leanback.widget.DiffCallback)  
Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/leanback/widget/DiffCallback "View this page in Java")

<br />

```
abstract class DiffCallback<Value>
```

<br />

Known direct subclasses  
[GuidedActionDiffCallback](https://developer.android.com/reference/kotlin/androidx/leanback/widget/GuidedActionDiffCallback)  

|------------------------------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [GuidedActionDiffCallback](https://developer.android.com/reference/kotlin/androidx/leanback/widget/GuidedActionDiffCallback) | DiffCallback used for GuidedActions, see[setActionsDiffCallback](https://developer.android.com/reference/kotlin/androidx/leanback/app/GuidedStepSupportFragment#setActionsDiffCallback(androidx.leanback.widget.DiffCallback<androidx.leanback.widget.GuidedAction>)). |

*** ** * ** ***

Callback that informs[ArrayObjectAdapter](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ArrayObjectAdapter)how to compute list updates when using[DiffUtil](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil)in[setItems](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ArrayObjectAdapter#setItems(java.util.List,androidx.leanback.widget.DiffCallback))method.

The[setItems](https://developer.android.com/reference/kotlin/androidx/leanback/widget/ArrayObjectAdapter#setItems(java.util.List,androidx.leanback.widget.DiffCallback))method will pass items from different lists to this callback in order to implement the[DiffUtil.Callback](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil.Callback)it uses to compute differences between lists.  

| Parameters |
|------------|---------------------------|
| `<Value>`  | Type of items to compare. |

## Summary

|                                                 ### Public constructors                                                 |
|-------------------------------------------------------------------------------------------------------------------------|
| [DiffCallback](https://developer.android.com/reference/kotlin/androidx/leanback/widget/DiffCallback#DiffCallback())`()` |

|                                      ### Public functions                                      |
|------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [areContentsTheSame](https://developer.android.com/reference/kotlin/androidx/leanback/widget/DiffCallback#areContentsTheSame(Value,Value))`(oldItem: Value, newItem: Value)` Called to decide whether two items have the same data.                |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | [areItemsTheSame](https://developer.android.com/reference/kotlin/androidx/leanback/widget/DiffCallback#areItemsTheSame(Value,Value))`(oldItem: Value, newItem: Value)` Called to decide whether two objects represent the same item.               |
| [Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`?`                 | [getChangePayload](https://developer.android.com/reference/kotlin/androidx/leanback/widget/DiffCallback#getChangePayload(Value,Value))`(oldItem: Value, newItem: Value)` Called to get a change payload between an old and new version of an item. |

## Public constructors

### DiffCallback

Added in 1.1.0  

```
DiffCallback()
```  

## Public functions

### areContentsTheSame

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
abstract fun areContentsTheSame(oldItem: Value, newItem: Value): Boolean
```

Called to decide whether two items have the same data. This information is used to detect if the contents of an item have changed.  

|    Parameters    |
|------------------|---------------------------|
| `oldItem: Value` | The item in the old list. |
| `newItem: Value` | The item in the new list. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if the contents of the items are the same or false if they are different. |

|                                                                    See also                                                                     |
|-------------------------------------------------------------------------------------------------------------------------------------------------|---|
| [areContentsTheSame](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil.Callback#areContentsTheSame(int,int)) |   |

### areItemsTheSame

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
abstract fun areItemsTheSame(oldItem: Value, newItem: Value): Boolean
```

Called to decide whether two objects represent the same item.  

|    Parameters    |
|------------------|---------------------------|
| `oldItem: Value` | The item in the old list. |
| `newItem: Value` | The item in the new list. |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|---------------------------------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | True if the two items represent the same object or false if they are different. |

|                                                                 See also                                                                  |
|-------------------------------------------------------------------------------------------------------------------------------------------|---|
| [areItemsTheSame](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil.Callback#areItemsTheSame(int,int)) |   |

### getChangePayload

Added in[1.1.0](https://developer.android.com/jetpack/androidx/releases/leanback#1.1.0)  

```
fun getChangePayload(oldItem: Value, newItem: Value): Any?
```

Called to get a change payload between an old and new version of an item.  

|                                                                  See also                                                                   |
|---------------------------------------------------------------------------------------------------------------------------------------------|---|
| [getChangePayload](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil.Callback#getChangePayload(int,int)) |   |