-
public abstract class FragmentPagerAdapter extends PagerAdapter
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
When using FragmentPagerAdapter the host ViewPager must have a valid ID set.
Subclasses only need to implement getItem 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/FragmentPagerSupport.java * complete}
The
R.layout.fragment_pagerresource of the top-level fragment is: {@sample frameworks/support/samples/Support13Demos/src/main/res/layout/fragment_pager.xml * complete}The
R.layout.fragment_pager_listresource containing each individual fragment's layout is: {@sample frameworks/support/samples/Support13Demos/src/main/res/layout/fragment_pager_list.xml * complete}
-
-
Constructor Summary
Constructors Constructor Description FragmentPagerAdapter(FragmentManager fm)
-
Method Summary
Modifier and Type Method Description abstract FragmentgetItem(int position)Return the Fragment associated with a specified position. voidstartUpdate(ViewGroup container)ObjectinstantiateItem(ViewGroup container, int position)voiddestroyItem(ViewGroup container, int position, Object object)voidsetPrimaryItem(ViewGroup container, int position, Object object)voidfinishUpdate(ViewGroup container)booleanisViewFromObject(View view, Object object)ParcelablesaveState()voidrestoreState(Parcelable state, ClassLoader loader)longgetItemId(int position)Return a unique identifier for the item at the given position. -
Methods inherited from class tds.androidx.viewpager.PagerAdapter
destroyItem, destroyItem, finishUpdate, finishUpdate, getCount, getItemPosition, getPageTitle, getPageWidth, instantiateItem, instantiateItem, isViewFromObject, notifyDataSetChanged, registerDataSetObserver, restoreState, setPrimaryItem, setPrimaryItem, startUpdate, startUpdate, unregisterDataSetObserver -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
FragmentPagerAdapter
FragmentPagerAdapter(FragmentManager fm)
-
-
Method Detail
-
getItem
@Deprecated() abstract Fragment getItem(int position)
Return the Fragment associated with a specified position.
-
startUpdate
@Deprecated() void startUpdate(ViewGroup container)
-
instantiateItem
@Deprecated() Object instantiateItem(ViewGroup container, int position)
-
destroyItem
@Deprecated() void destroyItem(ViewGroup container, int position, Object object)
-
setPrimaryItem
@Deprecated() void setPrimaryItem(ViewGroup container, int position, Object object)
-
finishUpdate
@Deprecated() void finishUpdate(ViewGroup container)
-
isViewFromObject
@Deprecated() boolean isViewFromObject(View view, Object object)
-
saveState
@Deprecated() Parcelable saveState()
-
restoreState
@Deprecated() void restoreState(Parcelable state, ClassLoader loader)
-
getItemId
@Deprecated() long getItemId(int position)
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.
- Parameters:
position- Position within this adapter
-
-
-
-