# BatchingListUpdateCallback

# BatchingListUpdateCallback

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

*** ** * ** ***

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

<br />

```
class BatchingListUpdateCallback : ListUpdateCallback
```

<br />

*** ** * ** ***

Wraps a[ListUpdateCallback](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ListUpdateCallback)callback and batches operations that can be merged.

For instance, when 2 add operations comes that adds 2 consecutive elements, BatchingListUpdateCallback merges them and calls the wrapped callback only once.

This is a general purpose class and is also used by[DiffResult](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/DiffUtil.DiffResult)and[SortedList](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/SortedList)to minimize the number of updates that are dispatched.

If you use this class to batch updates, you must call[dispatchLastEvent](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/BatchingListUpdateCallback#dispatchLastEvent())when the stream of update events drain.

## Summary

|                                                                                                                                                               ### Public constructors                                                                                                                                                                |
|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [BatchingListUpdateCallback](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/BatchingListUpdateCallback#BatchingListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback))`(callback: `[ListUpdateCallback](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/ListUpdateCallback)`)` |

|                             ### Public functions                              |
|-------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [dispatchLastEvent](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/BatchingListUpdateCallback#dispatchLastEvent())`()` BatchingListUpdateCallback holds onto the last event to see if it can be merged with the next one.                                                                                                                                                                                                                                                  |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onChanged](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/BatchingListUpdateCallback#onChanged(int,int,java.lang.Object))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, count: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, payload: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`!)` Called when count} number of items are updated at the given position. |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onInserted](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/BatchingListUpdateCallback#onInserted(int,int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, count: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when count} number of items are inserted at the given position.                                                                                                        |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onMoved](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/BatchingListUpdateCallback#onMoved(int,int))`(fromPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, toPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when an item changes its position in the list.                                                                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | [onRemoved](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/BatchingListUpdateCallback#onRemoved(int,int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, count: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Called when count} number of items are removed from the given position.                                                                                                         |

## Public constructors

### BatchingListUpdateCallback

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

```
BatchingListUpdateCallback(callback: ListUpdateCallback)
```  

## Public functions

### dispatchLastEvent

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

```
fun dispatchLastEvent(): Unit
```

BatchingListUpdateCallback holds onto the last event to see if it can be merged with the next one. When stream of events finish, you should call this method to dispatch the last event.  

### onChanged

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

```
fun onChanged(position: Int, count: Int, payload: Any!): Unit
```

Called when count} number of items are updated at the given position.  

### onInserted

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

```
fun onInserted(position: Int, count: Int): Unit
```

Called when count} number of items are inserted at the given position.  

### onMoved

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

```
fun onMoved(fromPosition: Int, toPosition: Int): Unit
```

Called when an item changes its position in the list.  

### onRemoved

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

```
fun onRemoved(position: Int, count: Int): Unit
```

Called when count} number of items are removed from the given position.