# AsyncListUtil.DataCallback

# AsyncListUtil.DataCallback

Artifact:[androidx.recyclerview:recyclerview](https://developer.android.com/jetpack/androidx/releases/recyclerview)  
[View Source](https://cs.android.com/search?q=file:androidx/recyclerview/widget/AsyncListUtil.java+class:androidx.recyclerview.widget.AsyncListUtil.DataCallback)  
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/AsyncListUtil.DataCallback "View this page in Java")

<br />

```
abstract class AsyncListUtil.DataCallback<T>
```

<br />

*** ** * ** ***

The callback that provides data access for[AsyncListUtil](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil).

All methods are called on the background thread.

## Summary

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

|                                   ### Public functions                                   |
|------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `abstract `[Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html) | `@`[WorkerThread](https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread) [fillData](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil.DataCallback#fillData(T[],int,int))`(data: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<T!>, startPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Fill the given tile.                                                                    |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)              | `@`[WorkerThread](https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread) [getMaxCachedTiles](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil.DataCallback#getMaxCachedTiles())`()` Returns tile cache size limit (in tiles).                                                                                                                                                                                                                                                                                                                           |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)            | `@`[WorkerThread](https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread) [recycleData](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil.DataCallback#recycleData(T[],int))`(data: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<T!>, itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Recycle the objects created in[fillData](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil.DataCallback#fillData(T[],int,int))if necessary. |
| `abstract `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)   | `@`[WorkerThread](https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread) [refreshData](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil.DataCallback#refreshData())`()` Refresh the data set and return the new data item count.                                                                                                                                                                                                                                                                                                                        |

## Public constructors

### DataCallback

Added in 1.0.0  

```
DataCallback()
```  

## Public functions

### fillData

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

```
@WorkerThread
abstract fun fillData(data: Array<T!>, startPosition: Int, itemCount: Int): Unit
```

Fill the given tile.

The provided tile might be a recycled tile, in which case it will already have objects. It is suggested to re-use these objects if possible in your use case.  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------|
| `data: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<T!>` | The data item array to fill into. Should not be accessed beyond`itemCount`. |
| `startPosition: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)  | The start position in the list.                                             |
| `itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)      | The data item count.                                                        |

### getMaxCachedTiles

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

```
@WorkerThread
fun getMaxCachedTiles(): Int
```

Returns tile cache size limit (in tiles).

The actual number of cached tiles will be the maximum of this value and the number of tiles that is required to cover the range returned by[extendRangeInto](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil.ViewCallback#extendRangeInto(int[],int[],int)).

For example, if this method returns 10, and the most recent call to[extendRangeInto](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil.ViewCallback#extendRangeInto(int[],int[],int))returned {100, 179}, and the tile size is 5, then the maximum number of cached tiles will be 16.

However, if the tile size is 20, then the maximum number of cached tiles will be 10.

The default implementation returns 10.  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|---------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Maximum cache size. |

### recycleData

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

```
@WorkerThread
fun recycleData(data: Array<T!>, itemCount: Int): Unit
```

Recycle the objects created in[fillData](https://developer.android.com/reference/kotlin/androidx/recyclerview/widget/AsyncListUtil.DataCallback#fillData(T[],int,int))if necessary.  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|----------------------------------------------------------------|
| `data: `[Array](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-array/index.html)`<T!>` | Array of data items. Should not be accessed beyond`itemCount`. |
| `itemCount: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)      | The data item count.                                           |

### refreshData

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

```
@WorkerThread
abstract fun refreshData(): Int
```

Refresh the data set and return the new data item count.

If the data is being accessed through[android.database.Cursor](https://developer.android.com/reference/android/database/Cursor.html)this is where the new cursor should be created.  

|                                   Returns                                   |
|-----------------------------------------------------------------------------|------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | Data item count. |