# PagingSource.LoadResult.Page

Artifact: [androidx.paging:paging-common](https://developer.android.com/jetpack/androidx/releases/paging) [View Source](https://cs.android.com/search?q=file:androidx/paging/PagingSource.kt+class:androidx.paging.PagingSource.LoadResult.Page) Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

*** ** * ** ***


```
public final class PagingSource.LoadResult.Page<Key extends Object, Value extends Object> extends PagingSource.LoadResult<@NonNull Key, @NonNull Value> implements Iterable<@NonNull Value>
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [androidx.paging.PagingSource.LoadResult](https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult)\<@[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull) Key, @[NonNull](https://developer.android.com/reference/androidx/annotation/NonNull) Value\> ||
|   | ↳ | [androidx.paging.PagingSource.LoadResult.Page](https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page) |

*** ** * ** ***

Success result object for `https://developer.android.com/reference/androidx/paging/PagingSource#load(androidx.paging.PagingSource.LoadParams)`.

As a convenience, iterating on this object will iterate through its loaded `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#data()`.

```kotlin
import androidx.paging.PagingSource
import androidx.paging.PagingSource.LoadResult

// One common method of pagination is to use next (and optionally previous) tokens.
// The below code shows you how to
data class NetworkResponseObject(
    val items: List<Item>,
    val next: String,
    val approximateItemsRemaining: Int,
)

// The following shows how you use convert such a response loaded in PagingSource.load() to
// a Page, which can be returned from that method
fun NetworkResponseObject.toPage() =
    LoadResult.Page(
        data = items,
        prevKey = null, // this implementation can only append, can't load a prepend
        nextKey = next, // next token will be the params.key of a subsequent append load
        itemsAfter = approximateItemsRemaining,
    )
```

```kotlin
import androidx.paging.PagingSource
import androidx.paging.PagingSource.LoadResult

// If you load by page number, the response may not define how to load the next page.
data class NetworkResponseObject(val items: List<Item>)

// The following shows how you use the current page number (e.g., the current key in
// PagingSource.load() to convert a response into a Page, which can be returned from that method
fun NetworkResponseObject.toPage(pageNumber: Int): LoadResult.Page<Int, Item> {
    return LoadResult.Page(
        data = items,
        // Since 0 is the lowest page number, return null to signify no more pages
        // should be loaded before it.
        prevKey = if (pageNumber > 0) pageNumber - 1 else null,
        // This API defines that it's out of data when a page returns empty. When out of
        // data, we return `null` to signify no more pages should be loaded
        // If the response instead
        nextKey = if (items.isNotEmpty()) pageNumber + 1 else null,
    )
}
```

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#COUNT_UNDEFINED()` |

| ### Public constructors |
|---|
| `<Key extends https://developer.android.com/reference/java/lang/Object.html, Value extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#Page(kotlin.collections.List,kotlin.Any,kotlin.Any)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull Value> data, Key prevKey, Key nextKey )` Success result object for `https://developer.android.com/reference/androidx/paging/PagingSource#load(androidx.paging.PagingSource.LoadParams)`. |
| `<Key extends https://developer.android.com/reference/java/lang/Object.html, Value extends https://developer.android.com/reference/java/lang/Object.html> https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#Page(kotlin.collections.List,kotlin.Any,kotlin.Any,kotlin.Int,kotlin.Int)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull Value> data, Key prevKey, Key nextKey, @https://developer.android.com/reference/androidx/annotation/IntRange(from = -2147483648) int itemsBefore, @https://developer.android.com/reference/androidx/annotation/IntRange(from = -2147483648) int itemsAfter )` |

| ### Public methods |
|---|---|
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull Value>` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#getData()()` Loaded data |
| `final int` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#getItemsAfter()()` Count of items after the loaded data. |
| `final int` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#getItemsBefore()()` Count of items before the loaded data. |
| `final Key` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#getNextKey()()` `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page` for next page if more data can be loaded in that direction, `null` otherwise. |
| `final Key` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#getPrevKey()()` `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page` for previous page if more data can be loaded in that direction, `null` otherwise. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/Iterator.html<@https://developer.android.com/reference/androidx/annotation/NonNull Value>` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#iterator()()` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page#toString()()` |

## Constants

### COUNT_UNDEFINED

```
public static final int COUNT_UNDEFINED
```

## Public constructors

### Page

```
public <Key extends Object, Value extends Object> Page(
    @NonNull List<@NonNull Value> data,
    Key prevKey,
    Key nextKey
)
```

Success result object for `https://developer.android.com/reference/androidx/paging/PagingSource#load(androidx.paging.PagingSource.LoadParams)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/util/List.html<@https://developer.android.com/reference/androidx/annotation/NonNull Value> data` | Loaded data |
| `Key prevKey` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page` for previous page if more data can be loaded in that direction, `null` otherwise. |
| `Key nextKey` | `https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page` for next page if more data can be loaded in that direction, `null` otherwise. |

### Page

```
public <Key extends Object, Value extends Object> Page(
    @NonNull List<@NonNull Value> data,
    Key prevKey,
    Key nextKey,
    @IntRange(from = -2147483648) int itemsBefore,
    @IntRange(from = -2147483648) int itemsAfter
)
```

## Public methods

### getData

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public final @NonNull List<@NonNull Value> getData()
```

Loaded data

### getItemsAfter

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public final int getItemsAfter()
```

Count of items after the loaded data. Must be implemented if `https://developer.android.com/reference/androidx/paging/PagingSource#jumpingSupported()` is enabled. Optional otherwise.

### getItemsBefore

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public final int getItemsBefore()
```

Count of items before the loaded data. Must be implemented if `https://developer.android.com/reference/androidx/paging/PagingSource#jumpingSupported()` is enabled. Optional otherwise.

### getNextKey

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public final Key getNextKey()
```

`https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page` for next page if more data can be loaded in that direction, `null` otherwise.

### getPrevKey

Added in [3.0.0](https://developer.android.com/jetpack/androidx/releases/paging#3.0.0)

```
public final Key getPrevKey()
```

`https://developer.android.com/reference/androidx/paging/PagingSource.LoadResult.Page` for previous page if more data can be loaded in that direction, `null` otherwise.

### iterator

Added in [3.2.0](https://developer.android.com/jetpack/androidx/releases/paging#3.2.0)

```
public @NonNull Iterator<@NonNull Value> iterator()
```

### toString

```
public @NonNull String toString()
```