abstract class FragmentPagerAdapter : PagerAdapter
   ↳ androidx.viewpager.widget.PagerAdapter

Implementation of PagerAdapter that represents each page as a Fragment that is persistently kept in the fragment manager as long as the user can return to the page.

This version of the pager is best for use when there are a handful of typically more static fragments to be paged through, such as a set of tabs. The fragment of each page the user visits will be kept in memory, though its view hierarchy may be destroyed when not visible. This can result in using a significant amount of memory since fragment instances can hold on to an arbitrary amount of state. For larger sets of pages, consider FragmentStatePagerAdapter.

When using FragmentPagerAdapter the host ViewPager must have a valid ID set.

Subclasses only need to implement getItem(int) and getCount() to have a working adapter.

Here is an example implementation of a pager containing fragments of lists: {@sample frameworks/support/samples/Support4Demos/src/main/java/com/example/android/supportv4/app/ * complete}

The R.layout.fragment_pager resource of the top-level fragment is: {@sample frameworks/support/samples/Support4Demos/src/main/res/layout/fragment_pager.xml * complete}

The R.layout.fragment_pager_list resource containing each individual fragment's layout is: {@sample frameworks/support/samples/Support4Demos/src/main/res/layout/fragment_pager_list.xml * complete}


Inherited constants
Public constructors
<init>(@NonNull fm: FragmentManager)

Public methods
open Any
instantiateItem(@NonNull container: ViewGroup, position: Int)

open Unit
finishUpdate(@NonNull container: ViewGroup)

abstract Fragment
getItem(position: Int)

Return the Fragment associated with a specified position.

open Unit
restoreState(@Nullable state: Parcelable?, @Nullable loader: ClassLoader?)

open Parcelable?

open Boolean
isViewFromObject(@NonNull view: View, @NonNull object: Any)

open Long
getItemId(position: Int)

Return a unique identifier for the item at the given position.

open Unit
startUpdate(@NonNull container: ViewGroup)

open Unit
setPrimaryItem(@NonNull container: ViewGroup, position: Int, @NonNull object: Any)

open Unit
destroyItem(@NonNull container: ViewGroup, position: Int, @NonNull object: Any)

Inherited functions

Public constructors


FragmentPagerAdapter(@NonNull fm: FragmentManager)

Public methods


@NonNull open fun instantiateItem(@NonNull container: ViewGroup, position: Int): Any


open fun finishUpdate(@NonNull container: ViewGroup): Unit


@NonNull abstract fun getItem(position: Int): Fragment

Return the Fragment associated with a specified position.


open fun restoreState(@Nullable state: Parcelable?, @Nullable loader: ClassLoader?): Unit


@Nullable open fun saveState(): Parcelable?


open fun isViewFromObject(@NonNull view: View, @NonNull object: Any): Boolean


open fun getItemId(position: Int): Long

Return a unique identifier for the item at the given position.

The default implementation returns the given position. Subclasses should override this method if the positions of items can change.

position Int: Position within this adapter
Long: Unique identifier for the item at position


open fun startUpdate(@NonNull container: ViewGroup): Unit


open fun setPrimaryItem(@NonNull container: ViewGroup, position: Int, @NonNull object: Any): Unit


open fun destroyItem(@NonNull container: ViewGroup, position: Int, @NonNull object: Any): Unit