FragmentPagerAdapter is a subclass of the PagerAdapter class from the Android compatibility package that represents each page, in the ViewPager where is used, as a Fragment.
FragmentPagerAdapter represent each page as a Fragment. This adapter class should be used only when there is a limited number of Fragments to swipe in the ViewPager. Using the FragmentPagerAdapter would require at minimum implementing the getItem()(to return the Fragment for this position) and getCount()(to return the number of Fragments in this adapter) methods.
From the documentation of the FragmentPagerAdapter
class:
Implementation of
PagerAdapter
that represents each page as aFragment
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 hostViewPager
must have a valid ID set.Subclasses only need to implement
getItem(int)
andgetCount()
to have a working adapter.
Tag Usage:
android android-viewpager android-pageradapter fragmentstatepageradapter android-fragments