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

*** ** * ** ***


```
public class BatchingListUpdateCallback implements ListUpdateCallback
```

<br />

*** ** * ** ***

Wraps a `https://developer.android.com/reference/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 `https://developer.android.com/reference/androidx/recyclerview/widget/DiffUtil.DiffResult` and `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList` to minimize the number of updates that are dispatched.

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

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/BatchingListUpdateCallback#BatchingListUpdateCallback(androidx.recyclerview.widget.ListUpdateCallback)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/recyclerview/widget/ListUpdateCallback callback)` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/BatchingListUpdateCallback#dispatchLastEvent()()` BatchingListUpdateCallback holds onto the last event to see if it can be merged with the next one. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/BatchingListUpdateCallback#onChanged(int,int,java.lang.Object)(int position, int count, https://developer.android.com/reference/java/lang/Object.html payload)` Called when count} number of items are updated at the given position. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/BatchingListUpdateCallback#onInserted(int,int)(int position, int count)` Called when count} number of items are inserted at the given position. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/BatchingListUpdateCallback#onMoved(int,int)(int fromPosition, int toPosition)` Called when an item changes its position in the list. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/BatchingListUpdateCallback#onRemoved(int,int)(int position, int count)` 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)

```
public BatchingListUpdateCallback(@NonNull ListUpdateCallback callback)
```

## Public methods

### dispatchLastEvent

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

```
public void dispatchLastEvent()
```

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)

```
public void onChanged(int position, int count, Object payload)
```

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)

```
public void onInserted(int position, int count)
```

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)

```
public void onMoved(int fromPosition, int toPosition)
```

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)

```
public void onRemoved(int position, int count)
```

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