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

*** ** * ** ***

Common/AllAndroid/JVMNative/C/iOSJavaScript
- Cmn

  ```
  data class PagingSource.LoadResult.Page<Key : Any, Value : Any> : PagingSource.LoadResult<Key, Value>, Iterable<Value>
  ```

|---|---|---|
| [kotlin.Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) |||
| ↳ | [androidx.paging.PagingSource.LoadResult](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult)\<Key, Value\> ||
|   | ↳ | [androidx.paging.PagingSource.LoadResult.Page](https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page) |

*** ** * ** ***

Success result object for `https://developer.android.com/reference/kotlin/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/kotlin/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 |
|---|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#COUNT_UNDEFINED()` | Cmn |

| ### Public constructors |
|---|---|
| `<Key : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, Value : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#Page(kotlin.collections.List,kotlin.Any,kotlin.Any)(data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<Value>, prevKey: Key?, nextKey: Key?)` Success result object for `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource#load(androidx.paging.PagingSource.LoadParams)`. | Cmn |
| `<Key : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html, Value : https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html> https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#Page(kotlin.collections.List,kotlin.Any,kotlin.Any,kotlin.Int,kotlin.Int)( data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<Value>, prevKey: Key?, nextKey: Key?, itemsBefore: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = -2147483648) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, itemsAfter: @https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = -2147483648) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` | Cmn |

| ### Public functions |
|---|---|---|
| `open operator https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-iterator/index.html<Value>` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#iterator()()` | Cmn |
| `open https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#toString()()` | Cmn |

| ### Public properties |
|---|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<Value>` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#data()` Loaded data | Cmn |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = -2147483648) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#itemsAfter()` Count of items after the loaded data. | Cmn |
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntRange(from = -2147483648) https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#itemsBefore()` Count of items before the loaded data. | Cmn |
| `Key?` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#nextKey()` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` for next page if more data can be loaded in that direction, `null` otherwise. | Cmn |
| `Key?` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page#prevKey()` `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` for previous page if more data can be loaded in that direction, `null` otherwise. | Cmn |

## Constants

### COUNT_UNDEFINED

Cmn

```
const val COUNT_UNDEFINED: Int
```

## Public constructors

### Page

Cmn

```
<Key : Any, Value : Any> Page(data: List<Value>, prevKey: Key?, nextKey: Key?)
```

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

| Parameters |
|---|---|
| `data: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin.collections/-list/index.html<Value>` | Loaded data |
| `prevKey: Key?` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` for previous page if more data can be loaded in that direction, `null` otherwise. |
| `nextKey: Key?` | `https://developer.android.com/reference/kotlin/androidx/paging/PagingSource.LoadResult.Page` for next page if more data can be loaded in that direction, `null` otherwise. |

### Page

Cmn

```
<Key : Any, Value : Any> Page(
    data: List<Value>,
    prevKey: Key?,
    nextKey: Key?,
    itemsBefore: @IntRange(from = -2147483648) Int = COUNT_UNDEFINED,
    itemsAfter: @IntRange(from = -2147483648) Int = COUNT_UNDEFINED
)
```

## Public functions

### iterator

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

```
open operator fun iterator(): Iterator<Value>
```

### toString

Cmn

```
open fun toString(): String
```

## Public properties

### data

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

```
val data: List<Value>
```

Loaded data

### itemsAfter

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

```
val itemsAfter: @IntRange(from = -2147483648) Int
```

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

### itemsBefore

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

```
val itemsBefore: @IntRange(from = -2147483648) Int
```

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

### nextKey

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

```
val nextKey: Key?
```

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

### prevKey

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

```
val prevKey: Key?
```

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