# PagedList.Builder

Summary:[Ctors](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#pubctors)\|[Methods](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#inhmethods)  

# PagedList.Builder

| The`android.arch`Architecture Components packages are no longer maintained. They have been superseded by the corresponding[androidx.\*](https://developer.android.com/jetpack/androidx/migrate)packages. See[androidx.paging.PagedList.Builder](https://developer.android.com/reference/androidx/paging/PagedList.Builder)instead.

`
public
static
final

class
PagedList.Builder
`  
`

extends Object


``


`

|---|-----------------------------------------------------|
| java.lang.Object                                       ||
| ↳ | android.arch.paging.PagedList.Builder\<Key, Value\> |

<br />

*** ** * ** ***

Builder class for PagedList.

DataSource, Config, main thread and background executor must all be provided.

A PagedList queries initial data from its DataSource during construction, to avoid empty PagedLists being presented to the UI when possible. It's preferred to present initial data, so that the UI doesn't show an empty list, or placeholders for a few frames, just before showing initial content.

[LivePagedListBuilder](https://developer.android.com/reference/android/arch/paging/LivePagedListBuilder)does this creation on a background thread automatically, if you want to receive a`LiveData<PagedList<...>>`.

## Summary

|                                                                                                                                                                                                                                                                                                                            ### Public constructors                                                                                                                                                                                                                                                                                                                             ||
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[PagedList.Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#PagedList.Builder(android.arch.paging.DataSource<Key, Value>, android.arch.paging.PagedList.Config))`(`[DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)`<Key, Value> dataSource, `[PagedList.Config](https://developer.android.com/reference/android/arch/paging/PagedList.Config)` config) ` Create a PagedList.Builder with the provided[DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)and[PagedList.Config](https://developer.android.com/reference/android/arch/paging/PagedList.Config). |
| ` `[PagedList.Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#PagedList.Builder(android.arch.paging.DataSource<Key, Value>, int))`(`[DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)`<Key, Value> dataSource, int pageSize) ` Create a PagedList.Builder with the provided[DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)and page size.                                                                                                                                                                                                                     |

|                                                                                                                                                                                                                          ### Public methods                                                                                                                                                                                                                           ||
|-----------------------------------------------------------------------------------------------------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` `[PagedList](https://developer.android.com/reference/android/arch/paging/PagedList)`<Value>`            | ` `[build](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#build())`() ` Creates a[PagedList](https://developer.android.com/reference/android/arch/paging/PagedList)with the given parameters.                                                                                                                               |
| ` `[Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)`<Key, Value>` | ` `[setBoundaryCallback](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#setBoundaryCallback(android.arch.paging.PagedList.BoundaryCallback))`(`[BoundaryCallback](https://developer.android.com/reference/android/arch/paging/PagedList.BoundaryCallback)` boundaryCallback) ` The BoundaryCallback for out of data events. |
| ` `[Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)`<Key, Value>` | ` `[setFetchExecutor](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#setFetchExecutor(java.util.concurrent.Executor))`(Executor fetchExecutor) ` The executor used to fetch additional pages from the DataSource.                                                                                                           |
| ` `[Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)`<Key, Value>` | ` `[setInitialKey](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#setInitialKey(Key))`(Key initialKey) ` Sets the initial key the DataSource should load around as part of initialization.                                                                                                                                  |
| ` `[Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)`<Key, Value>` | ` `[setNotifyExecutor](https://developer.android.com/reference/android/arch/paging/PagedList.Builder#setNotifyExecutor(java.util.concurrent.Executor))`(Executor notifyExecutor) ` The executor defining where page loading updates are dispatched.                                                                                                        |

| ### 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

### PagedList.Builder

```
PagedList.Builder (DataSource<Key, Value> dataSource, 
                PagedList.Config config)
```

Create a PagedList.Builder with the provided[DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)and[PagedList.Config](https://developer.android.com/reference/android/arch/paging/PagedList.Config).

<br />

|                                                   Parameters                                                   ||
|--------------|--------------------------------------------------------------------------------------------------|
| `dataSource` | `DataSource`: DataSource the PagedList will load from. <br />                                    |
| `config`     | `PagedList.Config`: Config that defines how the PagedList loads data from its DataSource. <br /> |

### PagedList.Builder

```
PagedList.Builder (DataSource<Key, Value> dataSource, 
                int pageSize)
```

Create a PagedList.Builder with the provided[DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)and page size.

This method is a convenience for:  

```
 PagedList.Builder(dataSource,
         new PagedList.Config.Builder().setPageSize(pageSize).build());
 
```

<br />

<br />

|                                            Parameters                                             ||
|--------------|-------------------------------------------------------------------------------------|
| `dataSource` | `DataSource`: DataSource the PagedList will load from. <br />                       |
| `pageSize`   | `int`: Config that defines how the PagedList loads data from its DataSource. <br /> |

## Public methods

### build

```
PagedList<Value> build ()
```

Creates a[PagedList](https://developer.android.com/reference/android/arch/paging/PagedList)with the given parameters.

This call will dispatch the[DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)'s loadInitial method immediately. If a DataSource posts all of its work (e.g. to a network thread), the PagedList will be immediately created as empty, and grow to its initial size when the initial load completes.

If the DataSource implements its load synchronously, doing the load work immediately in the loadInitial method, the PagedList will block on that load before completing construction. In this case, use a background thread to create a PagedList.

It's fine to create a PagedList with an async DataSource on the main thread, such as in the constructor of a ViewModel. An async network load won't block the initialLoad function. For a synchronous DataSource such as one created from a Room database, a`LiveData<PagedList>`can be safely constructed with[LivePagedListBuilder](https://developer.android.com/reference/android/arch/paging/LivePagedListBuilder)on the main thread, since actual construction work is deferred, and done on a background thread.

While build() will always return a PagedList, it's important to note that the PagedList initial load may fail to acquire data from the DataSource. This can happen for example if the DataSource is invalidated during its initial load. If this happens, the PagedList will be immediately[detached](https://developer.android.com/reference/android/arch/paging/PagedList#isDetached()), and you can retry construction (including setting a new DataSource).

<br />

|                                                               Returns                                                               ||
|---------------------------------------------------------------------------------------------|----------------------------------------|
| [PagedList](https://developer.android.com/reference/android/arch/paging/PagedList)`<Value>` | The newly constructed PagedList <br /> |

### setBoundaryCallback

```
Builder<Key, Value> setBoundaryCallback (BoundaryCallback boundaryCallback)
```

The BoundaryCallback for out of data events.

Pass a BoundaryCallback to listen to when the PagedList runs out of data to load.

<br />

|                                              Parameters                                              ||
|--------------------|----------------------------------------------------------------------------------|
| `boundaryCallback` | `BoundaryCallback`: BoundaryCallback for listening to out-of-data events. <br /> |

|                                                       Returns                                                       ||
|--------------------------------------------------------------------------------------------------------|-------------|
| [Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)`<Key, Value>` | this <br /> |

### setFetchExecutor

```
Builder<Key, Value> setFetchExecutor (Executor fetchExecutor)
```

The executor used to fetch additional pages from the DataSource. Does not affect initial load, which will be done immediately on whichever thread the PagedList is created on.

<br />

|                                                                    Parameters                                                                    ||
|-----------------|---------------------------------------------------------------------------------------------------------------------------------|
| `fetchExecutor` | `Executor`: Executor used to fetch from DataSources, generally a background thread pool for e.g. I/O or network loading. <br /> |

|                                                       Returns                                                       ||
|--------------------------------------------------------------------------------------------------------|-------------|
| [Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)`<Key, Value>` | this <br /> |

### setInitialKey

```
Builder<Key, Value> setInitialKey (Key initialKey)
```

Sets the initial key the DataSource should load around as part of initialization.

<br />

|                                          Parameters                                          ||
|--------------|--------------------------------------------------------------------------------|
| `initialKey` | `Key`: Key the DataSource should load around as part of initialization. <br /> |

|                                                       Returns                                                       ||
|--------------------------------------------------------------------------------------------------------|-------------|
| [Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)`<Key, Value>` | this <br /> |

### setNotifyExecutor

```
Builder<Key, Value> setNotifyExecutor (Executor notifyExecutor)
```

The executor defining where page loading updates are dispatched.

<br />

|                                                                                                                        Parameters                                                                                                                        ||
|------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `notifyExecutor` | `Executor`: Executor that receives PagedList updates, and where[PagedList.Callback](https://developer.android.com/reference/android/arch/paging/PagedList.Callback)calls are dispatched. Generally, this is the ui/main thread. <br /> |

|                                                       Returns                                                       ||
|--------------------------------------------------------------------------------------------------------|-------------|
| [Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)`<Key, Value>` | this <br /> |

-

  ## Interfaces

  - [DataSource.InvalidatedCallback](https://developer.android.com/reference/android/arch/paging/DataSource.InvalidatedCallback)
-

  ## Classes

  - [AsyncPagedListDiffer](https://developer.android.com/reference/android/arch/paging/AsyncPagedListDiffer)
  - [DataSource](https://developer.android.com/reference/android/arch/paging/DataSource)
  - [DataSource.Factory](https://developer.android.com/reference/android/arch/paging/DataSource.Factory)
  - [ItemKeyedDataSource](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource)
  - [ItemKeyedDataSource.LoadCallback](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource.LoadCallback)
  - [ItemKeyedDataSource.LoadInitialCallback](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialCallback)
  - [ItemKeyedDataSource.LoadInitialParams](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource.LoadInitialParams)
  - [ItemKeyedDataSource.LoadParams](https://developer.android.com/reference/android/arch/paging/ItemKeyedDataSource.LoadParams)
  - [LivePagedListBuilder](https://developer.android.com/reference/android/arch/paging/LivePagedListBuilder)
  - [PagedList](https://developer.android.com/reference/android/arch/paging/PagedList)
  - [PagedList.BoundaryCallback](https://developer.android.com/reference/android/arch/paging/PagedList.BoundaryCallback)
  - [PagedList.Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Builder)
  - [PagedList.Callback](https://developer.android.com/reference/android/arch/paging/PagedList.Callback)
  - [PagedList.Config](https://developer.android.com/reference/android/arch/paging/PagedList.Config)
  - [PagedList.Config.Builder](https://developer.android.com/reference/android/arch/paging/PagedList.Config.Builder)
  - [PagedListAdapter](https://developer.android.com/reference/android/arch/paging/PagedListAdapter)
  - [PageKeyedDataSource](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource)
  - [PageKeyedDataSource.LoadCallback](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadCallback)
  - [PageKeyedDataSource.LoadInitialCallback](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadInitialCallback)
  - [PageKeyedDataSource.LoadInitialParams](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadInitialParams)
  - [PageKeyedDataSource.LoadParams](https://developer.android.com/reference/android/arch/paging/PageKeyedDataSource.LoadParams)
  - [PositionalDataSource](https://developer.android.com/reference/android/arch/paging/PositionalDataSource)
  - [PositionalDataSource.LoadInitialCallback](https://developer.android.com/reference/android/arch/paging/PositionalDataSource.LoadInitialCallback)
  - [PositionalDataSource.LoadInitialParams](https://developer.android.com/reference/android/arch/paging/PositionalDataSource.LoadInitialParams)
  - [PositionalDataSource.LoadRangeCallback](https://developer.android.com/reference/android/arch/paging/PositionalDataSource.LoadRangeCallback)
  - [PositionalDataSource.LoadRangeParams](https://developer.android.com/reference/android/arch/paging/PositionalDataSource.LoadRangeParams)
  - [RxPagedListBuilder](https://developer.android.com/reference/android/arch/paging/RxPagedListBuilder)