# PagerAdapter

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

*** ** * ** ***

Kotlin\|[Java](https://developer.android.com/reference/androidx/viewpager/widget/PagerAdapter "View this page in Java")

<br />

```
abstract class PagerAdapter
```

<br />

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

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

*** ** * ** ***

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

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

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

PagerAdapter is more general than the adapters used for[AdapterViews](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[startUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup))indicates that the contents of the ViewPager are about to change. One or more calls to[instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int))and/or[destroyItem](https://developer.android.com/reference/kotlin/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[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)). By the time[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup))returns the views associated with the key objects returned by[instantiateItem](https://developer.android.com/reference/kotlin/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[destroyItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object))should be removed. The method[isViewFromObject](https://developer.android.com/reference/kotlin/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[instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int))after creation and adding them to the parent ViewGroup. A matching[destroyItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object))implementation would remove the View from the parent ViewGroup and[isViewFromObject](https://developer.android.com/reference/kotlin/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[notifyDataSetChanged](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#notifyDataSetChanged())similar to AdapterView adapters derived from[android.widget.BaseAdapter](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[getItemPosition](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getItemPosition(java.lang.Object)).

## Summary

|                                    ### Constants                                    |
|-------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------|
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [POSITION_NONE](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#POSITION_NONE())` = -2`           |
| `const `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | [POSITION_UNCHANGED](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED())` = -1` |

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

|                                       ### Public functions                                        |
|---------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | ~~[destroyItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.View,int,java.lang.Object))~~`(container: `[View](https://developer.android.com/reference/android/view/View.html)`, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`)` **This function is deprecated.** Use[destroyItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object)) <br />             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [destroyItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.ViewGroup,int,java.lang.Object))`(container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html)`, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`)` Remove a page for the given position.                                                                                                                                                                     |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | ~~[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.View))~~`(container: `[View](https://developer.android.com/reference/android/view/View.html)`)` **This function is deprecated.** Use[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)) <br />                                                                                                                                                                                                                                   |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup))`(container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html)`)` Called when the a change in the shown pages has been completed.                                                                                                                                                                                                                                                                                                                                              |
| `abstract `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)            | [getCount](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getCount())`()` Return the number of views available.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)                       | [getItemPosition](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getItemPosition(java.lang.Object))`(object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`)` Called when the host view is attempting to determine if an item's position has changed.                                                                                                                                                                                                                                                                                                                              |
| [CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | [getPageTitle](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getPageTitle(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` This method may be called by the ViewPager to obtain a title string to describe the specified page.                                                                                                                                                                                                                                                                                                                                   |
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)                   | [getPageWidth](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getPageWidth(int))`(position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Returns the proportional width of a given page as a percentage of the ViewPager's measured width from (0.f-1.f\]                                                                                                                                                                                                                                                                                                                      |
| [Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                       | ~~[instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int))~~`(container: `[View](https://developer.android.com/reference/android/view/View.html)`, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` **This function is deprecated.** Use[instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)) <br />                                                                                                                      |
| [Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)                       | [instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int))`(container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html)`, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`)` Create the page for the given position.                                                                                                                                                                                                                                                                   |
| `abstract `[Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html)    | [isViewFromObject](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#isViewFromObject(android.view.View,java.lang.Object))`(view: `[View](https://developer.android.com/reference/android/view/View.html)`, object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`)` Determines whether a page View is associated with a specific key object as returned by[instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.ViewGroup,int)).                                                                      |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [notifyDataSetChanged](https://developer.android.com/reference/kotlin/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.                                                                                                                                                                                                                                                                                                                                                                                |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [registerDataSetObserver](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#registerDataSetObserver(android.database.DataSetObserver))`(observer: `[DataSetObserver](https://developer.android.com/reference/android/database/DataSetObserver.html)`)` Register an observer to receive callbacks related to the adapter's data changing.                                                                                                                                                                                                                                                                             |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [restoreState](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#restoreState(android.os.Parcelable,java.lang.ClassLoader))`(state: `[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)`?, loader: `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)`?)` Restore any instance state associated with this adapter and its pages that was previously saved by[saveState](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#saveState()).                                                                            |
| [Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)`?`               | [saveState](https://developer.android.com/reference/kotlin/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.                                                                                                                                                                                                                                                                                                                                                                                         |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | ~~[setPrimaryItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.View,int,java.lang.Object))~~`(container: `[View](https://developer.android.com/reference/android/view/View.html)`, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`)` **This function is deprecated.** Use[setPrimaryItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.ViewGroup,int,java.lang.Object)) <br /> |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [setPrimaryItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.ViewGroup,int,java.lang.Object))`(container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html)`, position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)`, object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)`)` 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.                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | ~~[startUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.View))~~`(container: `[View](https://developer.android.com/reference/android/view/View.html)`)` **This function is deprecated.** Use[startUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup)) <br />                                                                                                                                                                                                                                       |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [startUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup))`(container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html)`)` Called when a change in the shown pages is going to start being made.                                                                                                                                                                                                                                                                                                                                          |
| [Unit](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)                     | [unregisterDataSetObserver](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#unregisterDataSetObserver(android.database.DataSetObserver))`(observer: `[DataSetObserver](https://developer.android.com/reference/android/database/DataSetObserver.html)`)` 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)  

```
const val POSITION_NONE = -2: Int
```  

### POSITION_UNCHANGED

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

```
const val POSITION_UNCHANGED = -1: Int
```  

## Public constructors

### PagerAdapter

Added in 1.1.0  

```
PagerAdapter()
```  

## Public functions

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

```
fun [destroyItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#destroyItem(android.view.View,int,java.lang.Object))(container: View, position: Int, object: Any): Unit
```
| **This function is deprecated.**   
|
| Use[destroyItem](https://developer.android.com/reference/kotlin/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[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.View)).  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `container: `[View](https://developer.android.com/reference/android/view/View.html)     | The containing View from which the page will be removed.                                                                                                                             |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The page position to be removed.                                                                                                                                                     |
| `object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)   | The same object that was returned by[instantiateItem](https://developer.android.com/reference/kotlin/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)  

```
fun destroyItem(container: ViewGroup, position: Int, object: Any): Unit
```

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[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)).  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) | The containing View from which the page will be removed.                                                                                                                             |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)       | The page position to be removed.                                                                                                                                                     |
| `object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)         | The same object that was returned by[instantiateItem](https://developer.android.com/reference/kotlin/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)  

```
fun [finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.View))(container: View): Unit
```
| **This function is deprecated.**   
|
| Use[finishUpdate](https://developer.android.com/reference/kotlin/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                                      |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| `container: `[View](https://developer.android.com/reference/android/view/View.html) | 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)  

```
fun finishUpdate(container: ViewGroup): Unit
```

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                                           |
|-----------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| `container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) | 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)  

```
abstract fun getCount(): Int
```

Return the number of views available.  

### getItemPosition

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

```
fun getItemPosition(object: Any): Int
```

Called when the host view is attempting to determine if an item's position has changed. Returns[POSITION_UNCHANGED](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED())if the position of the given item has not changed or[POSITION_NONE](https://developer.android.com/reference/kotlin/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[POSITION_UNCHANGED](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED()).  

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) | Object representing an item, previously returned by a call to[instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int)). |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | object's new position index from \[0,[getCount](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#getCount())),[POSITION_UNCHANGED](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#POSITION_UNCHANGED())if the object's position has not changed, or[POSITION_NONE](https://developer.android.com/reference/kotlin/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)  

```
fun getPageTitle(position: Int): CharSequence?
```

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                                        |
|-----------------------------------------------------------------------------------------|-------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The position of the title requested |

|                                              Returns                                              |
|---------------------------------------------------------------------------------------------------|--------------------------------|
| [CharSequence](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-char-sequence/index.html)`?` | A title for the requested page |

### getPageWidth

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

```
fun getPageWidth(position: Int): Float
```

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

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|------------------------------------|
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The position of the page requested |

|                                     Returns                                     |
|---------------------------------------------------------------------------------|------------------------------------------------|
| [Float](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html) | 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)  

```
fun [instantiateItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#instantiateItem(android.view.View,int))(container: View, position: Int): Any
```
| **This function is deprecated.**   
|
| Use[instantiateItem](https://developer.android.com/reference/kotlin/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[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)).  

|                                       Parameters                                        |
|-----------------------------------------------------------------------------------------|------------------------------------------------------|
| `container: `[View](https://developer.android.com/reference/android/view/View.html)     | The containing View in which the page will be shown. |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The page position to be instantiated.                |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| [Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.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)  

```
fun instantiateItem(container: ViewGroup, position: Int): Any
```

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[finishUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#finishUpdate(android.view.ViewGroup)).  

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|------------------------------------------------------|
| `container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) | The containing View in which the page will be shown. |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)       | The page position to be instantiated.                |

|                                   Returns                                   |
|-----------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------|
| [Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.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)  

```
abstract fun isViewFromObject(view: View, object: Any): Boolean
```

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

|                                      Parameters                                       |
|---------------------------------------------------------------------------------------|-------------------------------------------------|
| `view: `[View](https://developer.android.com/reference/android/view/View.html)        | Page View to check for association with`object` |
| `object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html) | Object to check for association with`view`      |

|                                       Returns                                       |
|-------------------------------------------------------------------------------------|--------------------------------------------------------|
| [Boolean](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html) | 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)  

```
fun notifyDataSetChanged(): Unit
```

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)  

```
fun registerDataSetObserver(observer: DataSetObserver): Unit
```

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

|                                                  Parameters                                                  |
|--------------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `observer: `[DataSetObserver](https://developer.android.com/reference/android/database/DataSetObserver.html) | The[android.database.DataSetObserver](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)  

```
fun restoreState(state: Parcelable?, loader: ClassLoader?): Unit
```

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

|                                           Parameters                                           |
|------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------|
| `state: `[Parcelable](https://developer.android.com/reference/android/os/Parcelable.html)`?`   | State previously saved by a call to[saveState](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#saveState()) |
| `loader: `[ClassLoader](https://developer.android.com/reference/java/lang/ClassLoader.html)`?` | 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)  

```
fun saveState(): Parcelable?
```

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                                       |
|-------------------------------------------------------------------------------------|------------------------------|
| [Parcelable](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)  

```
fun [setPrimaryItem](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#setPrimaryItem(android.view.View,int,java.lang.Object))(container: View, position: Int, object: Any): Unit
```
| **This function is deprecated.**   
|
| Use[setPrimaryItem](https://developer.android.com/reference/kotlin/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                                        |
|-----------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `container: `[View](https://developer.android.com/reference/android/view/View.html)     | The containing View from which the page will be removed.                                                                                                                             |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html) | The page position that is now the primary.                                                                                                                                           |
| `object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)   | The same object that was returned by[instantiateItem](https://developer.android.com/reference/kotlin/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)  

```
fun setPrimaryItem(container: ViewGroup, position: Int, object: Any): Unit
```

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                                           |
|-----------------------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) | The containing View from which the page will be removed.                                                                                                                             |
| `position: `[Int](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)       | The page position that is now the primary.                                                                                                                                           |
| `object: `[Any](https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-any/index.html)         | The same object that was returned by[instantiateItem](https://developer.android.com/reference/kotlin/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)  

```
fun [startUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.View))(container: View): Unit
```
| **This function is deprecated.**   
|
| Use[startUpdate](https://developer.android.com/reference/kotlin/androidx/viewpager/widget/PagerAdapter#startUpdate(android.view.ViewGroup))

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

|                                     Parameters                                      |
|-------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| `container: `[View](https://developer.android.com/reference/android/view/View.html) | 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)  

```
fun startUpdate(container: ViewGroup): Unit
```

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

|                                          Parameters                                           |
|-----------------------------------------------------------------------------------------------|--------------------------------------------------------------------|
| `container: `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup.html) | 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)  

```
fun unregisterDataSetObserver(observer: DataSetObserver): Unit
```

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

|                                                  Parameters                                                  |
|--------------------------------------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------|
| `observer: `[DataSetObserver](https://developer.android.com/reference/android/database/DataSetObserver.html) | The[android.database.DataSetObserver](https://developer.android.com/reference/android/database/DataSetObserver.html)which will be unregistered. |