FragmentStatePagerAdapter

abstract class FragmentStatePagerAdapter
kotlin.Any
   ↳ androidx.fragment.app.FragmentStatePagerAdapter

Implementation of PagerAdapter that uses a Fragment to manage each page. This class also handles saving and restoring of fragment's state.

This version of the pager is more useful when there are a large number of pages, working more like a list view. When pages are not visible to the user, their entire fragment may be destroyed, only keeping the saved state of that fragment. This allows the pager to hold on to much less memory associated with each visited page as compared to FragmentPagerAdapter at the cost of potentially more overhead when switching between pages.

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/Support13Demos/src/main/java/com/example/android/supportv13/app/FragmentStatePagerSupport.java * complete}

The R.layout.fragment_pager resource of the top-level fragment is: {@sample frameworks/support/samples/Support13Demos/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/Support13Demos/src/main/res/layout/fragment_pager_list.xml * complete}

Summary

Public constructors

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

open Unit
restoreState(state: Parcelable!, loader: ClassLoader!)

open Parcelable!

open Boolean
isViewFromObject(view: View!, object: Any!)

open Unit
startUpdate(container: ViewGroup!)

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

open Unit
finishUpdate(container: ViewGroup!)

abstract Fragment!
getItem(position: Int)

Return the Fragment associated with a specified position.

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

Public constructors

<init>

FragmentStatePagerAdapter(fm: FragmentManager!)

Public methods

instantiateItem

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

restoreState

open fun restoreState(state: Parcelable!, loader: ClassLoader!): Unit

saveState

open fun saveState(): Parcelable!

isViewFromObject

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

startUpdate

open fun startUpdate(container: ViewGroup!): Unit

setPrimaryItem

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

finishUpdate

open fun finishUpdate(container: ViewGroup!): Unit

getItem

abstract fun getItem(position: Int): Fragment!

Return the Fragment associated with a specified position.

destroyItem

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