|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectandroid.support.v4.view.PagerAdapter
android.support.v4.app.FragmentStatePagerAdapter
public abstract class 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 PagerAdapter.getCount() to have a working adapter.
Here is an example implementation of a pager containing fragments of lists:
The R.layout.fragment_pager resource of the top-level fragment is:
The R.layout.fragment_pager_list resource containing each
individual fragment's layout is:
| Field Summary |
|---|
| Fields inherited from class android.support.v4.view.PagerAdapter |
|---|
POSITION_NONE, POSITION_UNCHANGED |
| Constructor Summary | |
|---|---|
FragmentStatePagerAdapter(FragmentManager fm)
|
|
| Method Summary | |
|---|---|
void |
destroyItem(android.view.ViewGroup container,
int position,
Object object)
Remove a page for the given position. |
void |
finishUpdate(android.view.ViewGroup container)
Called when the a change in the shown pages has been completed. |
abstract Fragment |
getItem(int position)
Return the Fragment associated with a specified position. |
Object |
instantiateItem(android.view.ViewGroup container,
int position)
Create the page for the given position. |
boolean |
isViewFromObject(android.view.View view,
Object object)
Determines whether a page View is associated with a specific key object as returned by PagerAdapter.instantiateItem(ViewGroup, int). |
void |
restoreState(android.os.Parcelable state,
ClassLoader loader)
Restore any instance state associated with this adapter and its pages that was previously saved by PagerAdapter.saveState(). |
android.os.Parcelable |
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. |
void |
setPrimaryItem(android.view.ViewGroup container,
int position,
Object 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. |
void |
startUpdate(android.view.ViewGroup container)
Called when a change in the shown pages is going to start being made. |
| Methods inherited from class android.support.v4.view.PagerAdapter |
|---|
destroyItem, finishUpdate, getCount, getItemPosition, getPageTitle, getPageWidth, instantiateItem, notifyDataSetChanged, registerDataSetObserver, setPrimaryItem, startUpdate, unregisterDataSetObserver |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public FragmentStatePagerAdapter(FragmentManager fm)
| Method Detail |
|---|
public abstract Fragment getItem(int position)
public void startUpdate(android.view.ViewGroup container)
PagerAdapter
startUpdate in class PagerAdaptercontainer - The containing View which is displaying this adapter's
page views.
public Object instantiateItem(android.view.ViewGroup container,
int position)
PagerAdapterPagerAdapter.finishUpdate(ViewGroup).
instantiateItem in class PagerAdaptercontainer - The containing View in which the page will be shown.position - The page position to be instantiated.
public void destroyItem(android.view.ViewGroup container,
int position,
Object object)
PagerAdapterPagerAdapter.finishUpdate(ViewGroup).
destroyItem in class PagerAdaptercontainer - The containing View from which the page will be removed.position - The page position to be removed.object - The same object that was returned by
PagerAdapter.instantiateItem(View, int).
public void setPrimaryItem(android.view.ViewGroup container,
int position,
Object object)
PagerAdapter
setPrimaryItem in class PagerAdaptercontainer - The containing View from which the page will be removed.position - The page position that is now the primary.object - The same object that was returned by
PagerAdapter.instantiateItem(View, int).public void finishUpdate(android.view.ViewGroup container)
PagerAdapter
finishUpdate in class PagerAdaptercontainer - The containing View which is displaying this adapter's
page views.
public boolean isViewFromObject(android.view.View view,
Object object)
PagerAdapterPagerAdapter.instantiateItem(ViewGroup, int). This method is
required for a PagerAdapter to function properly.
isViewFromObject in class PagerAdapterview - Page View to check for association with objectobject - Object to check for association with view
view is associated with the key object objectpublic android.os.Parcelable saveState()
PagerAdapter
saveState in class PagerAdapter
public void restoreState(android.os.Parcelable state,
ClassLoader loader)
PagerAdapterPagerAdapter.saveState().
restoreState in class PagerAdapterstate - State previously saved by a call to PagerAdapter.saveState()loader - A ClassLoader that should be used to instantiate any restored objects
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||