Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

DataCallback

abstract class DataCallback<T : Any!>
kotlin.Any
   ↳ androidx.recyclerview.widget.AsyncListUtil.DataCallback

The callback that provides data access for AsyncListUtil.

All methods are called on the background thread.

Summary

Public constructors

The callback that provides data access for AsyncListUtil.

Public methods
abstract Int

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

open Unit
recycleData(@NonNull data: Array<T>, itemCount: Int)

Recycle the objects created in fillData if necessary.

open Int

Returns tile cache size limit (in tiles).

abstract Unit
fillData(@NonNull data: Array<T>, startPosition: Int, itemCount: Int)

Fill the given tile.

Public constructors

<init>

DataCallback()

The callback that provides data access for AsyncListUtil.

All methods are called on the background thread.

Public methods

refreshData

@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 this is where the new cursor should be created.

Return
Int: Data item count.

recycleData

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

Recycle the objects created in fillData if necessary.

Parameters
data Array<T>: Array of data items. Should not be accessed beyond itemCount.
itemCount Array<T>: The data item count.

getMaxCachedTiles

@WorkerThread open 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 ViewCallback#extendRangeInto(int[], int[], int).

For example, if this method returns 10, and the most recent call to 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.

Return
Int: Maximum cache size.

fillData

@WorkerThread abstract fun fillData(@NonNull 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
startPosition Array<T>: The start position in the list.
itemCount Array<T>: The data item count.
data Array<T>: The data item array to fill into. Should not be accessed beyond itemCount.