Stay organized with collections
Save and categorize content based on your preferences.
ItemKeyedDataSource.LoadInitialCallback
public
static
abstract
class
ItemKeyedDataSource.LoadInitialCallback
extends LoadCallback<Value>
Callback for loadInitial(LoadInitialParams, LoadInitialCallback)
to return data and, optionally, position/count information.
A callback can be called only once, and will throw if called again.
If you can compute the number of items in the data set before and after the loaded range,
call the three parameter onResult(List, int, int)
to pass that information. You
can skip passing this information by calling the single parameter onResult(List)
,
either if it's difficult to compute, or if placeholdersEnabled
is
false
, so the positioning information will be ignored.
It is always valid for a DataSource loading method that takes a callback to stash the
callback and call it later. This enables DataSources to be fully asynchronous, and to handle
temporary, recoverable error states (such as a network error that can be retried).
Summary
Public methods |
abstract
void
|
onResult(List<Value> data, int position, int totalCount)
Called to pass initial load state from a DataSource.
|
Inherited methods |
|
From class
java.lang.Object
Object
|
clone()
|
boolean
|
equals(Object arg0)
|
void
|
finalize()
|
final
Class<?>
|
getClass()
|
int
|
hashCode()
|
final
void
|
notify()
|
final
void
|
notifyAll()
|
String
|
toString()
|
final
void
|
wait(long arg0, int arg1)
|
final
void
|
wait(long arg0)
|
final
void
|
wait()
|
|
Public constructors
ItemKeyedDataSource.LoadInitialCallback
ItemKeyedDataSource.LoadInitialCallback ()
Public methods
onResult
void onResult (List<Value> data,
int position,
int totalCount)
Called to pass initial load state from a DataSource.
Call this method from your DataSource's loadInitial
function to return data,
and inform how many placeholders should be shown before and after. If counting is cheap
to compute (for example, if a network load returns the information regardless), it's
recommended to pass data back through this method.
It is always valid to pass a different amount of data than what is requested. Pass an
empty list if there is no more data to load.
Parameters |
data |
List : List of items loaded from the DataSource. If this is empty, the DataSource
is treated as empty, and no further loads will occur. |
position |
int : Position of the item at the front of the list. If there are N
items before the items in data that can be loaded from this DataSource,
pass N . |
totalCount |
int : Total number of items that may be returned from this DataSource.
Includes the number in the initial data parameter
as well as any items that can be loaded in front or behind of
data .
|
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[null,null,["Last updated 2025-02-10 UTC."],[],[],null,["# ItemKeyedDataSource.LoadInitialCallback\n\nSummary: [Ctors](#pubctors) \\| [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nItemKeyedDataSource.LoadInitialCallback\n=======================================\n\n| The `android.arch` Architecture Components packages are no longer maintained. They have been superseded by the corresponding [androidx.\\*](/jetpack/androidx/migrate) packages. See [androidx.paging.ItemKeyedDataSource.LoadInitialCallback](/reference/androidx/paging/ItemKeyedDataSource.LoadInitialCallback) instead.\n\n\n`\npublic\nstatic\n\nabstract\nclass\nItemKeyedDataSource.LoadInitialCallback\n`\n\n\n`\n\n\n`\n\n`\n\nextends `[LoadCallback](/reference/android/arch/paging/ItemKeyedDataSource.LoadCallback)`\u003cValue\u003e\n\n\n`\n\n`\n\n\n`\n\n|---|---|----------------------------------------------------------------------|\n| java.lang.Object |||\n| ↳ | [android.arch.paging.ItemKeyedDataSource.LoadCallback](/reference/android/arch/paging/ItemKeyedDataSource.LoadCallback)\\\u003cValue\\\u003e ||\n| | ↳ | android.arch.paging.ItemKeyedDataSource.LoadInitialCallback\\\u003cValue\\\u003e |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nCallback for [loadInitial(LoadInitialParams, LoadInitialCallback)](/reference/android/arch/paging/ItemKeyedDataSource#loadInitial(android.arch.paging.ItemKeyedDataSource.LoadInitialParams\u003cKey\u003e, android.arch.paging.ItemKeyedDataSource.LoadInitialCallback\u003cValue\u003e))\nto return data and, optionally, position/count information.\n\n\nA callback can be called only once, and will throw if called again.\n\n\nIf you can compute the number of items in the data set before and after the loaded range,\ncall the three parameter [onResult(List, int, int)](/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialCallback#onResult(java.util.List\u003cValue\u003e, int, int)) to pass that information. You\ncan skip passing this information by calling the single parameter [onResult(List)](/reference/android/arch/paging/ItemKeyedDataSource.LoadCallback#onResult(java.util.List\u003cValue\u003e)),\neither if it's difficult to compute, or if [placeholdersEnabled](/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialParams#placeholdersEnabled) is\n`false`, so the positioning information will be ignored.\n\n\nIt is always valid for a DataSource loading method that takes a callback to stash the\ncallback and call it later. This enables DataSources to be fully asynchronous, and to handle\ntemporary, recoverable error states (such as a network error that can be retried).\n\nSummary\n-------\n\n| ### Public constructors ||\n|---------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|\n| ` `[ItemKeyedDataSource.LoadInitialCallback](/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialCallback#ItemKeyedDataSource.LoadInitialCallback())`() ` |\n\n| ### Public methods ||\n|------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` abstract void` | ` `[onResult](/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialCallback#onResult(java.util.List\u003cValue\u003e, int, int))`(List\u003cValue\u003e data, int position, int totalCount) ` Called to pass initial load state from a DataSource. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` `[android.arch.paging.ItemKeyedDataSource.LoadCallback](/reference/android/arch/paging/ItemKeyedDataSource.LoadCallback)` ` |------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract void` | ` `[onResult](/reference/android/arch/paging/ItemKeyedDataSource.LoadCallback#onResult(java.util.List\u003cValue\u003e))`(List\u003cValue\u003e data) ` Called to pass loaded data from a DataSource. | ||\n| From class ` java.lang.Object ` |-------------------|-------------------------------| | ` Object` | ` clone() ` | | ` boolean` | ` equals(Object arg0) ` | | ` void` | ` finalize() ` | | ` final Class\u003c?\u003e` | ` getClass() ` | | ` int` | ` hashCode() ` | | ` final void` | ` notify() ` | | ` final void` | ` notifyAll() ` | | ` String` | ` toString() ` | | ` final void` | ` wait(long arg0, int arg1) ` | | ` final void` | ` wait(long arg0) ` | | ` final void` | ` wait() ` | ||\n\nPublic constructors\n-------------------\n\n### ItemKeyedDataSource.LoadInitialCallback\n\n```\nItemKeyedDataSource.LoadInitialCallback ()\n```\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nPublic methods\n--------------\n\n### onResult\n\n```\nvoid onResult (List\u003cValue\u003e data, \n int position, \n int totalCount)\n```\n\nCalled to pass initial load state from a DataSource.\n\n\nCall this method from your DataSource's `loadInitial` function to return data,\nand inform how many placeholders should be shown before and after. If counting is cheap\nto compute (for example, if a network load returns the information regardless), it's\nrecommended to pass data back through this method.\n\n\nIt is always valid to pass a different amount of data than what is requested. Pass an\nempty list if there is no more data to load.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|--------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `data` | `List`: List of items loaded from the DataSource. If this is empty, the DataSource is treated as empty, and no further loads will occur. \u003cbr /\u003e |\n| `position` | `int`: Position of the item at the front of the list. If there are `N` items before the items in data that can be loaded from this DataSource, pass `N`. \u003cbr /\u003e |\n| `totalCount` | `int`: Total number of items that may be returned from this DataSource. Includes the number in the initial `data` parameter as well as any items that can be loaded in front or behind of `data`. \u003cbr /\u003e |\n\n-\n\n Interfaces\n ----------\n\n - [DataSource.InvalidatedCallback](/reference/android/arch/paging/DataSource.InvalidatedCallback)\n-\n\n Classes\n -------\n\n - [AsyncPagedListDiffer](/reference/android/arch/paging/AsyncPagedListDiffer)\n - [DataSource](/reference/android/arch/paging/DataSource)\n - [DataSource.Factory](/reference/android/arch/paging/DataSource.Factory)\n - [ItemKeyedDataSource](/reference/android/arch/paging/ItemKeyedDataSource)\n - [ItemKeyedDataSource.LoadCallback](/reference/android/arch/paging/ItemKeyedDataSource.LoadCallback)\n - [ItemKeyedDataSource.LoadInitialCallback](/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialCallback)\n - [ItemKeyedDataSource.LoadInitialParams](/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialParams)\n - [ItemKeyedDataSource.LoadParams](/reference/android/arch/paging/ItemKeyedDataSource.LoadParams)\n - [LivePagedListBuilder](/reference/android/arch/paging/LivePagedListBuilder)\n - [PagedList](/reference/android/arch/paging/PagedList)\n - [PagedList.BoundaryCallback](/reference/android/arch/paging/PagedList.BoundaryCallback)\n - [PagedList.Builder](/reference/android/arch/paging/PagedList.Builder)\n - [PagedList.Callback](/reference/android/arch/paging/PagedList.Callback)\n - [PagedList.Config](/reference/android/arch/paging/PagedList.Config)\n - [PagedList.Config.Builder](/reference/android/arch/paging/PagedList.Config.Builder)\n - [PagedListAdapter](/reference/android/arch/paging/PagedListAdapter)\n - [PageKeyedDataSource](/reference/android/arch/paging/PageKeyedDataSource)\n - [PageKeyedDataSource.LoadCallback](/reference/android/arch/paging/PageKeyedDataSource.LoadCallback)\n - [PageKeyedDataSource.LoadInitialCallback](/reference/android/arch/paging/PageKeyedDataSource.LoadInitialCallback)\n - [PageKeyedDataSource.LoadInitialParams](/reference/android/arch/paging/PageKeyedDataSource.LoadInitialParams)\n - [PageKeyedDataSource.LoadParams](/reference/android/arch/paging/PageKeyedDataSource.LoadParams)\n - [PositionalDataSource](/reference/android/arch/paging/PositionalDataSource)\n - [PositionalDataSource.LoadInitialCallback](/reference/android/arch/paging/PositionalDataSource.LoadInitialCallback)\n - [PositionalDataSource.LoadInitialParams](/reference/android/arch/paging/PositionalDataSource.LoadInitialParams)\n - [PositionalDataSource.LoadRangeCallback](/reference/android/arch/paging/PositionalDataSource.LoadRangeCallback)\n - [PositionalDataSource.LoadRangeParams](/reference/android/arch/paging/PositionalDataSource.LoadRangeParams)\n - [RxPagedListBuilder](/reference/android/arch/paging/RxPagedListBuilder)"]]