PageKeyedDataSource
  public
  
  
  abstract
  class
  PageKeyedDataSource
  
  
  
  
    extends DataSource<Key, Value>
  
  
  
  
  
  
| java.lang.Object | ||
| ↳ | android.arch.paging.DataSource<Key, Value> | |
| ↳ | android.arch.paging.PageKeyedDataSource<Key, Value> | |
Incremental data loader for page-keyed content, where requests return keys for next/previous pages.
 Implement a DataSource using PageKeyedDataSource if you need to use data from page N - 1
 to load page N. This is common, for example, in network APIs that include a next/previous
 link or key with each page load.
 
 The InMemoryByPageRepository in the
 PagingWithNetworkSample
 shows how to implement a network PageKeyedDataSource using
 Retrofit, while
 handling swipe-to-refresh, network errors, and retry.
Summary
| Nested classes | |
|---|---|
| 
        
        
        
        
        class | PageKeyedDataSource.LoadCallback<Key, Value>Callback for PageKeyedDataSource  | 
| 
        
        
        
        
        class | PageKeyedDataSource.LoadInitialCallback<Key, Value>Callback for  | 
| 
        
        
        
        
        class | PageKeyedDataSource.LoadInitialParams<Key>Holder object for inputs to  | 
| 
        
        
        
        
        class | PageKeyedDataSource.LoadParams<Key>Holder object for inputs to  | 
| Public constructors | |
|---|---|
| 
      PageKeyedDataSource()
       | |
| Public methods | |
|---|---|
| 
        abstract
        
        
        
        
        void | 
      loadAfter(LoadParams<Key> params, LoadCallback<Key, Value> callback)
      Append page with the key specified by  | 
| 
        abstract
        
        
        
        
        void | 
      loadBefore(LoadParams<Key> params, LoadCallback<Key, Value> callback)
      Prepend page with the key specified by  | 
| 
        abstract
        
        
        
        
        void | 
      loadInitial(LoadInitialParams<Key> params, LoadInitialCallback<Key, Value> callback)
      Load initial data. | 
| 
        
        
        
        final
        <ToValue>
        PageKeyedDataSource<Key, ToValue> | 
      map(Function<Value, ToValue> function)
      Applies the given function to each value emitted by the DataSource. | 
| 
        
        
        
        final
        <ToValue>
        PageKeyedDataSource<Key, ToValue> | 
      mapByPage(Function<List<Value>, List<ToValue>> function)
      Applies the given function to each value emitted by the DataSource. | 
| Inherited methods | |
|---|---|
Public constructors
PageKeyedDataSource
PageKeyedDataSource ()
Public methods
loadAfter
void loadAfter (LoadParams<Key> params, LoadCallback<Key, Value> callback)
Append page with the key specified by LoadParams.key.
 
It's valid to return a different list size than the page size if it's easier, e.g. if your backend defines page sizes. It is generally safer to increase the number loaded than reduce.
Data may be passed synchronously during the load method, or deferred and called at a later time. Further loads going down will be blocked until the callback is called.
 If data cannot be loaded (for example, if the request is invalid, or the data would be stale
 and inconsistent, it is valid to call invalidate() to invalidate the data source,
 and prevent further loading.
| Parameters | |
|---|---|
| params | LoadParams: Parameters for the load, including the key for the new page, and requested load
               size. | 
| callback | LoadCallback: Callback that receives loaded data. | 
loadBefore
void loadBefore (LoadParams<Key> params, LoadCallback<Key, Value> callback)
Prepend page with the key specified by LoadParams.key.
 
It's valid to return a different list size than the page size if it's easier, e.g. if your backend defines page sizes. It is generally safer to increase the number loaded than reduce.
Data may be passed synchronously during the load method, or deferred and called at a later time. Further loads going down will be blocked until the callback is called.
 If data cannot be loaded (for example, if the request is invalid, or the data would be stale
 and inconsistent, it is valid to call invalidate() to invalidate the data source,
 and prevent further loading.
| Parameters | |
|---|---|
| params | LoadParams: Parameters for the load, including the key for the new page, and requested load
               size. | 
| callback | LoadCallback: Callback that receives loaded data. | 
loadInitial
void loadInitial (LoadInitialParams<Key> params, LoadInitialCallback<Key, Value> callback)
Load initial data.
 This method is called first to initialize a PagedList with data. If it's possible to count
 the items that can be loaded by the DataSource, it's recommended to pass the loaded data to
 the callback via the three-parameter
 onResult(List, int, int, Object, Object). This enables PagedLists
 presenting data from this source to display placeholders to represent unloaded items.
 
 requestedLoadSize is a hint, not a requirement, so it may be may be
 altered or ignored.
| Parameters | |
|---|---|
| params | LoadInitialParams: Parameters for initial load, including requested load size. | 
| callback | LoadInitialCallback: Callback that receives initial load data. | 
map
PageKeyedDataSource<Key, ToValue> map (Function<Value, ToValue> function)
Applies the given function to each value emitted by the DataSource.
 Same as mapByPage(Function), but operates on individual items.
| Parameters | |
|---|---|
| function | Function: Function that runs on each loaded item, returning items of a potentially
                  new type. | 
| Returns | |
|---|---|
| PageKeyedDataSource<Key, ToValue> | A new DataSource, which transforms items using the given function. | 
mapByPage
PageKeyedDataSource<Key, ToValue> mapByPage (Function<List<Value>, List<ToValue>> function)
Applies the given function to each value emitted by the DataSource.
 Same as map(Function), but allows for batch conversions.
| Parameters | |
|---|---|
| function | Function: Function that runs on each loaded page, returning items of a potentially
                  new type. | 
| Returns | |
|---|---|
| PageKeyedDataSource<Key, ToValue> | A new DataSource, which transforms items using the given function. | 
- Interfaces
- Classes- AsyncPagedListDiffer
- DataSource
- DataSource.Factory
- ItemKeyedDataSource
- ItemKeyedDataSource.LoadCallback
- ItemKeyedDataSource.LoadInitialCallback
- ItemKeyedDataSource.LoadInitialParams
- ItemKeyedDataSource.LoadParams
- LivePagedListBuilder
- PagedList
- PagedList.BoundaryCallback
- PagedList.Builder
- PagedList.Callback
- PagedList.Config
- PagedList.Config.Builder
- PagedListAdapter
- PageKeyedDataSource
- PageKeyedDataSource.LoadCallback
- PageKeyedDataSource.LoadInitialCallback
- PageKeyedDataSource.LoadInitialParams
- PageKeyedDataSource.LoadParams
- PositionalDataSource
- PositionalDataSource.LoadInitialCallback
- PositionalDataSource.LoadInitialParams
- PositionalDataSource.LoadRangeCallback
- PositionalDataSource.LoadRangeParams
- RxPagedListBuilder
 
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.
