# SortedListAdapterCallback

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

*** ** * ** ***


```
public abstract class SortedListAdapterCallback<T2> extends SortedList.Callback<T2>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.recyclerview.widget.SortedList.Callback](https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback)\<T2\> ||
|   | ↳ | [androidx.recyclerview.widget.SortedListAdapterCallback](https://developer.android.com/reference/androidx/recyclerview/widget/SortedListAdapterCallback) |

*** ** * ** ***

A `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback` implementation that can bind a `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList` to a `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter`.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/SortedListAdapterCallback#SortedListAdapterCallback(androidx.recyclerview.widget.RecyclerView.Adapter<?>)(https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter<@https://developer.android.com/reference/androidx/annotation/NonNull ?> adapter)` Creates a `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback` that will forward data change events to the provided Adapter. |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/SortedListAdapterCallback#onChanged(int,int)(int position, int count)` Called by the SortedList when the item at the given position is updated. |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/SortedListAdapterCallback#onChanged(int,int,java.lang.Object)(int position, int count, https://developer.android.com/reference/java/lang/Object.html payload)` |
| `void` | `https://developer.android.com/reference/androidx/recyclerview/widget/SortedListAdapterCallback#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/SortedListAdapterCallback#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/SortedListAdapterCallback#onRemoved(int,int)(int position, int count)` Called when count} number of items are removed from the given position. |

### Inherited methods

From [java.util.Comparator](https://developer.android.com/reference/java/util/Comparator.html) `abstract int` `https://developer.android.com/reference/java/util/Comparator.html#compare(T, T)(T p, T p1)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T, U extends https://developer.android.com/reference/java/lang/Comparable.html<U>> https://developer.android.com/reference/java/util/Comparator.html#comparing(java.util.function.Function&lt;? super T,? extends U&gt;)(https://developer.android.com/reference/java/util/function/Function.html<T, U> keyExtractor)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#comparingDouble(java.util.function.ToDoubleFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToDoubleFunction.html<T> keyExtractor)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#comparingInt(java.util.function.ToIntFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToIntFunction.html<T> keyExtractor)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#comparingLong(java.util.function.ToLongFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToLongFunction.html<T> keyExtractor)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T extends https://developer.android.com/reference/java/lang/Comparable.html<T>> https://developer.android.com/reference/java/util/Comparator.html#naturalOrder()()` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#nullsFirst(java.util.Comparator&lt;? super T&gt;)(https://developer.android.com/reference/java/util/Comparator.html<T> comparator)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T> https://developer.android.com/reference/java/util/Comparator.html#nullsLast(java.util.Comparator&lt;? super T&gt;)(https://developer.android.com/reference/java/util/Comparator.html<T> comparator)` `static https://developer.android.com/reference/java/util/Comparator.html<T>` `<T extends https://developer.android.com/reference/java/lang/Comparable.html<T>> https://developer.android.com/reference/java/util/Comparator.html#reverseOrder()()` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#reversed()()` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#thenComparing(java.util.Comparator&lt;? super T&gt;)(https://developer.android.com/reference/java/util/Comparator.html<T> other)` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#thenComparingDouble(java.util.function.ToDoubleFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToDoubleFunction.html<T> keyExtractor)` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#thenComparingInt(java.util.function.ToIntFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToIntFunction.html<T> keyExtractor)` `https://developer.android.com/reference/java/util/Comparator.html<T>` `https://developer.android.com/reference/java/util/Comparator.html#thenComparingLong(java.util.function.ToLongFunction&lt;? super T&gt;)(https://developer.android.com/reference/java/util/function/ToLongFunction.html<T> keyExtractor)` From [androidx.recyclerview.widget.ListUpdateCallback](https://developer.android.com/reference/androidx/recyclerview/widget/ListUpdateCallback) `abstract void` `https://developer.android.com/reference/androidx/recyclerview/widget/ListUpdateCallback#onChanged(int,int,java.lang.Object)(int position, int count, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html payload)`

Called when `count` number of items are updated at the given position.
From [androidx.recyclerview.widget.SortedList.Callback](https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback) `abstract boolean` `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback#areContentsTheSame(T2,T2)(T2 oldItem, T2 newItem)`

Called by the SortedList when it wants to check whether two items have the same data or not.
`abstract boolean` `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback#areItemsTheSame(T2,T2)(T2 item1, T2 item2)`

Called by the SortedList to decide whether two objects represent the same Item or not.
`abstract int` `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback#compare(T2,T2)(T2 o1, T2 o2)`

Similar to `https://developer.android.com/reference/java/util/Comparator.html#compare(T, T)`, should compare two and return how they should be ordered.
`@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/Object.html` `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback#getChangePayload(T2,T2)(T2 item1, T2 item2)`

When `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback#areItemsTheSame(T2,T2)` returns `true` for two items and `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback#areContentsTheSame(T2,T2)` returns false for them, `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback` calls this method to get a payload about the change.

## Public constructors

### SortedListAdapterCallback

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

```
public SortedListAdapterCallback(RecyclerView.Adapter<@NonNull ?> adapter)
```

Creates a `https://developer.android.com/reference/androidx/recyclerview/widget/SortedList.Callback` that will forward data change events to the provided Adapter.

| Parameters |
|---|---|
| `https://developer.android.com/reference/androidx/recyclerview/widget/RecyclerView.Adapter<@https://developer.android.com/reference/androidx/annotation/NonNull ?> adapter` | The Adapter instance which should receive events from the SortedList. |

## Public methods

### onChanged

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

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

Called by the SortedList when the item at the given position is updated.

### onChanged

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

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