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

ViewCallback

abstract class ViewCallback
kotlin.Any
   ↳ androidx.recyclerview.widget.AsyncListUtil.ViewCallback

The callback that links AsyncListUtil with the list view.

All methods are called on the main thread.

Summary

Constants
static Int

No scroll direction hint available.

static Int

Scrolling in descending order (from higher to lower positions in the order of the backing storage).

static Int

Scrolling in ascending order (from lower to higher positions in the order of the backing storage).

Public constructors

The callback that links AsyncListUtil with the list view.

Public methods
abstract Unit

Called when the entire data set has changed.

abstract Unit
getItemRangeInto(@NonNull outRange: IntArray)

Compute the range of visible item positions.

abstract Unit
onItemLoaded(position: Int)

Called when an item at the given position is loaded.

open Unit
extendRangeInto(@NonNull range: IntArray, @NonNull outRange: IntArray, scrollHint: Int)

Compute a wider range of items that will be loaded for smoother scrolling.

Constants

HINT_SCROLL_NONE

static val HINT_SCROLL_NONE: Int

No scroll direction hint available.

Value: 0

HINT_SCROLL_DESC

static val HINT_SCROLL_DESC: Int

Scrolling in descending order (from higher to lower positions in the order of the backing storage).

Value: 1

HINT_SCROLL_ASC

static val HINT_SCROLL_ASC: Int

Scrolling in ascending order (from lower to higher positions in the order of the backing storage).

Value: 2

Public constructors

<init>

ViewCallback()

The callback that links AsyncListUtil with the list view.

All methods are called on the main thread.

Public methods

onDataRefresh

@UiThread abstract fun onDataRefresh(): Unit

Called when the entire data set has changed.

getItemRangeInto

@UiThread abstract fun getItemRangeInto(@NonNull outRange: IntArray): Unit

Compute the range of visible item positions.

outRange[0] is the position of the first visible item (in the order of the backing storage).

outRange[1] is the position of the last visible item (in the order of the backing storage).

Negative positions and positions greater or equal to getItemCount are invalid. If the returned range contains invalid positions it is ignored (no item will be loaded).

Parameters
outRange IntArray: The visible item range.

onItemLoaded

@UiThread abstract fun onItemLoaded(position: Int): Unit

Called when an item at the given position is loaded.

Parameters
position Int: Item position.

extendRangeInto

@UiThread open fun extendRangeInto(@NonNull range: IntArray, @NonNull outRange: IntArray, scrollHint: Int): Unit

Compute a wider range of items that will be loaded for smoother scrolling.

If there is no scroll hint, the default implementation extends the visible range by half its length in both directions. If there is a scroll hint, the range is extended by its full length in the scroll direction, and by half in the other direction.

For example, if range is {100, 200} and scrollHint is HINT_SCROLL_ASC, then outRange will be {50, 300}.

However, if scrollHint is HINT_SCROLL_NONE, then outRange will be {50, 250}

Parameters
range IntArray: Visible item range.
outRange IntArray: Extended range.
scrollHint IntArray: The scroll direction hint.