# PagerAdapter

Artifact: [androidx.viewpager:viewpager](https://developer.android.com/jetpack/androidx/releases/viewpager) [View Source](https://cs.android.com/search?q=file:androidx/viewpager/widget/PagerAdapter.java+class:androidx.viewpager.widget.PagerAdapter) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0)

*** ** * ** ***


```
public abstract class PagerAdapter
```

<br />

Known direct subclasses [FragmentPagerAdapter](https://developer.android.com/reference/androidx/fragment/app/FragmentPagerAdapter), [FragmentStatePagerAdapter](https://developer.android.com/reference/androidx/fragment/app/FragmentStatePagerAdapter)

|---|---|
| `https://developer.android.com/reference/androidx/fragment/app/FragmentPagerAdapter` | **This class is deprecated.** Switch to `https://developer.android.com/reference/androidx/viewpager2/widget/ViewPager2` and use `https://developer.android.com/reference/androidx/viewpager2/adapter/FragmentStateAdapter` instead. <br /> |
| `https://developer.android.com/reference/androidx/fragment/app/FragmentStatePagerAdapter` | **This class is deprecated.** Switch to `https://developer.android.com/reference/androidx/viewpager2/widget/ViewPager2` and use `https://developer.android.com/reference/androidx/viewpager2/adapter/FragmentStateAdapter` instead. <br /> |

*** ** * ** ***

Base class providing the adapter to populate pages inside of a `https://developer.android.com/reference/androidx/viewpager/widget/ViewPager`. You will most likely want to use a more specific implementation of this, such as `https://developer.android.com/reference/androidx/fragment/app/FragmentPagerAdapter` or `https://developer.android.com/reference/androidx/fragment/app/FragmentStatePagerAdapter`.

When you implement a PagerAdapter, you must override the following methods at minimum:

- `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)`
- `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)`
- `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#getCount()`
- `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#isViewFromObject(android.view.View,java.lang.Object)`

PagerAdapter is more general than the adapters used for `https://developer.android.com/reference/android/widget/AdapterView.html`. Instead of providing a View recycling mechanism directly ViewPager uses callbacks to indicate the steps taken during an update. A PagerAdapter may implement a form of View recycling if desired or use a more sophisticated method of managing page Views such as Fragment transactions where each page is represented by its own Fragment.

ViewPager associates each page with a key Object instead of working with Views directly. This key is used to track and uniquely identify a given page independent of its position in the adapter. A call to the PagerAdapter method `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup)` indicates that the contents of the ViewPager are about to change. One or more calls to `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)` and/or `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)` will follow, and the end of an update will be signaled by a call to `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)`. By the time `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)` returns the views associated with the key objects returned by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)` should be added to the parent ViewGroup passed to these methods and the views associated with the keys passed to `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)` should be removed. The method `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#isViewFromObject(android.view.View,java.lang.Object)` identifies whether a page View is associated with a given key object.

A very simple PagerAdapter may choose to use the page Views themselves as key objects, returning them from `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)` after creation and adding them to the parent ViewGroup. A matching `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)` implementation would remove the View from the parent ViewGroup and `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#isViewFromObject(android.view.View,java.lang.Object)` could be implemented as `return view == object;`.

PagerAdapter supports data set changes. Data set changes must occur on the main thread and must end with a call to `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#notifyDataSetChanged()` similar to AdapterView adapters derived from `https://developer.android.com/reference/android/widget/BaseAdapter.html`. A data set change may involve pages being added, removed, or changing position. The ViewPager will keep the current page active provided the adapter implements the method `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#getItemPosition(java.lang.Object)`.

## Summary

| ### Constants |
|---|---|
| `static final int` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#POSITION_NONE() = -2` |
| `static final int` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED() = -1` |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#PagerAdapter()()` |

| ### Public methods |
|---|---|
| `void` | `[destroyItem](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.View,int,java.lang.Object))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container, int position, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)` <br /> |
| `void` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container, int position, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object )` Remove a page for the given position. |
| `void` | `[finishUpdate](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.View))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)` <br /> |
| `void` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container)` Called when the a change in the shown pages has been completed. |
| `abstract int` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#getCount()()` Return the number of views available. |
| `int` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#getItemPosition(java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object)` Called when the host view is attempting to determine if an item's position has changed. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/CharSequence.html` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#getPageTitle(int)(int position)` This method may be called by the ViewPager to obtain a title string to describe the specified page. |
| `float` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#getPageWidth(int)(int position)` Returns the proportional width of a given page as a percentage of the ViewPager's measured width from (0.f-1.f\] |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html` | `[instantiateItem](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container, int position)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)` <br /> |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container, int position)` Create the page for the given position. |
| `abstract boolean` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#isViewFromObject(android.view.View,java.lang.Object)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object)` Determines whether a page View is associated with a specific key object as returned by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)`. |
| `void` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#notifyDataSetChanged()()` This method should be called by the application if the data backing this adapter has changed and associated views should update. |
| `void` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#registerDataSetObserver(android.database.DataSetObserver)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/database/DataSetObserver.html observer)` Register an observer to receive callbacks related to the adapter's data changing. |
| `void` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#restoreState(android.os.Parcelable,java.lang.ClassLoader)(@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/os/Parcelable.html state, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/ClassLoader.html loader)` Restore any instance state associated with this adapter and its pages that was previously saved by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#saveState()`. |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/os/Parcelable.html` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#saveState()()` Save any instance state associated with this adapter and its pages that should be restored if the current UI state needs to be reconstructed. |
| `void` | `[setPrimaryItem](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.View,int,java.lang.Object))( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container, int position, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object )` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.ViewGroup,int,java.lang.Object)` <br /> |
| `void` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.ViewGroup,int,java.lang.Object)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container, int position, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object )` Called to inform the adapter of which item is currently considered to be the "primary", that is the one show to the user as the current page. |
| `void` | `[startUpdate](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.View))(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container)` **This method is deprecated.** Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup)` <br /> |
| `void` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container)` Called when a change in the shown pages is going to start being made. |
| `void` | `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#unregisterDataSetObserver(android.database.DataSetObserver)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/database/DataSetObserver.html observer)` Unregister an observer from callbacks related to the adapter's data changing. |

## Constants

### POSITION_NONE

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

```
public static final int POSITION_NONE = -2
```

### POSITION_UNCHANGED

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

```
public static final int POSITION_UNCHANGED = -1
```

## Public constructors

### PagerAdapter

Added in 1.1.0

```
public PagerAdapter()
```

## Public methods

### destroyItem

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0)

```
public void [destroyItem](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.View,int,java.lang.Object))(@NonNull View container, int position, @NonNull Object object)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)`

Remove a page for the given position. The adapter is responsible for removing the view from its container, although it only must ensure this is done by the time it returns from `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.View)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container` | The containing View from which the page will be removed. |
| `int position` | The page position to be removed. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object` | The same object that was returned by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int)`. |

### destroyItem

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

```
public void destroyItem(
    @NonNull ViewGroup container,
    int position,
    @NonNull Object object
)
```

Remove a page for the given position. The adapter is responsible for removing the view from its container, although it only must ensure this is done by the time it returns from `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container` | The containing View from which the page will be removed. |
| `int position` | The page position to be removed. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object` | The same object that was returned by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int)`. |

### finishUpdate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0)

```
public void [finishUpdate](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.View))(@NonNull View container)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)`

Called when the a change in the shown pages has been completed. At this point you must ensure that all of the pages have actually been added or removed from the container as appropriate.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container` | The containing View which is displaying this adapter's page views. |

### finishUpdate

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

```
public void finishUpdate(@NonNull ViewGroup container)
```

Called when the a change in the shown pages has been completed. At this point you must ensure that all of the pages have actually been added or removed from the container as appropriate.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container` | The containing View which is displaying this adapter's page views. |

### getCount

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

```
public abstract int getCount()
```

Return the number of views available.

### getItemPosition

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

```
public int getItemPosition(@NonNull Object object)
```

Called when the host view is attempting to determine if an item's position has changed. Returns `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED()` if the position of the given item has not changed or `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#POSITION_NONE()` if the item is no longer present in the adapter.

The default implementation assumes that items will never change position and always returns `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object` | Object representing an item, previously returned by a call to `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int)`. |

| Returns |
|---|---|
| `int` | object's new position index from \[0, `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#getCount()`), `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED()` if the object's position has not changed, or `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#POSITION_NONE()` if the item is no longer present. |

### getPageTitle

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

```
public @Nullable CharSequence getPageTitle(int position)
```

This method may be called by the ViewPager to obtain a title string to describe the specified page. This method may return null indicating no title for this page. The default implementation returns null.

| Parameters |
|---|---|
| `int position` | The position of the title requested |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/CharSequence.html` | A title for the requested page |

### getPageWidth

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

```
public float getPageWidth(int position)
```

Returns the proportional width of a given page as a percentage of the ViewPager's measured width from (0.f-1.f\]

| Parameters |
|---|---|
| `int position` | The position of the page requested |

| Returns |
|---|---|
| `float` | Proportional width for the given page position |

### instantiateItem

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0)

```
public @NonNull Object [instantiateItem](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int))(@NonNull View container, int position)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)`

Create the page for the given position. The adapter is responsible for adding the view to the container given here, although it only must ensure this is done by the time it returns from `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container` | The containing View in which the page will be shown. |
| `int position` | The page position to be instantiated. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html` | Returns an Object representing the new page. This does not need to be a View, but can be some other container of the page. |

### instantiateItem

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

```
public @NonNull Object instantiateItem(@NonNull ViewGroup container, int position)
```

Create the page for the given position. The adapter is responsible for adding the view to the container given here, although it only must ensure this is done by the time it returns from `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container` | The containing View in which the page will be shown. |
| `int position` | The page position to be instantiated. |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html` | Returns an Object representing the new page. This does not need to be a View, but can be some other container of the page. |

### isViewFromObject

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

```
public abstract boolean isViewFromObject(@NonNull View view, @NonNull Object object)
```

Determines whether a page View is associated with a specific key object as returned by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)`. This method is required for a PagerAdapter to function properly.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html view` | Page View to check for association with `object` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object` | Object to check for association with `view` |

| Returns |
|---|---|
| `boolean` | true if `view` is associated with the key object `object` |

### notifyDataSetChanged

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

```
public void notifyDataSetChanged()
```

This method should be called by the application if the data backing this adapter has changed and associated views should update.

### registerDataSetObserver

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

```
public void registerDataSetObserver(@NonNull DataSetObserver observer)
```

Register an observer to receive callbacks related to the adapter's data changing.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/database/DataSetObserver.html observer` | The `https://developer.android.com/reference/android/database/DataSetObserver.html` which will receive callbacks. |

### restoreState

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

```
public void restoreState(@Nullable Parcelable state, @Nullable ClassLoader loader)
```

Restore any instance state associated with this adapter and its pages that was previously saved by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#saveState()`.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/os/Parcelable.html state` | State previously saved by a call to `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#saveState()` |
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/java/lang/ClassLoader.html loader` | A ClassLoader that should be used to instantiate any restored objects |

### saveState

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

```
public @Nullable Parcelable saveState()
```

Save any instance state associated with this adapter and its pages that should be restored if the current UI state needs to be reconstructed.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/os/Parcelable.html` | Saved state for this adapter |

### setPrimaryItem

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0)

```
public void [setPrimaryItem](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.View,int,java.lang.Object))(
    @NonNull View container,
    int position,
    @NonNull Object object
)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.ViewGroup,int,java.lang.Object)`

Called to inform the adapter of which item is currently considered to be the "primary", that is the one show to the user as the current page.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container` | The containing View from which the page will be removed. |
| `int position` | The page position that is now the primary. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object` | The same object that was returned by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int)`. |

### setPrimaryItem

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

```
public void setPrimaryItem(
    @NonNull ViewGroup container,
    int position,
    @NonNull Object object
)
```

Called to inform the adapter of which item is currently considered to be the "primary", that is the one show to the user as the current page. This method will not be invoked when the adapter contains no items.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container` | The containing View from which the page will be removed. |
| `int position` | The page position that is now the primary. |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/Object.html object` | The same object that was returned by `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int)`. |

### startUpdate

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0) Deprecated in [1.1.0](https://developer.android.com/jetpack/androidx/releases/viewpager#1.1.0)

```
public void [startUpdate](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.View))(@NonNull View container)
```

> [!CAUTION]
> **This method is deprecated.**   
>
> Use `https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup)`

Called when a change in the shown pages is going to start being made.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/View.html container` | The containing View which is displaying this adapter's page views. |

### startUpdate

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

```
public void startUpdate(@NonNull ViewGroup container)
```

Called when a change in the shown pages is going to start being made.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/ViewGroup.html container` | The containing View which is displaying this adapter's page views. |

### unregisterDataSetObserver

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

```
public void unregisterDataSetObserver(@NonNull DataSetObserver observer)
```

Unregister an observer from callbacks related to the adapter's data changing.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/database/DataSetObserver.html observer` | The `https://developer.android.com/reference/android/database/DataSetObserver.html` which will be unregistered. |