Implementation of {@link android.support.v4.view.PagerAdapter} that
uses a {@link 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
{@link 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 {@link #getItem(int)}
and {@link #getCount()} to have a working adapter.
Here is an example implementation of a pager containing fragments of
lists:
{@sample development/samples/Support13Demos/src/com/example/android/supportv13/app/FragmentStatePagerSupport.java
complete}
The R.layout.fragment_pager resource of the top-level fragment is:
{@sample development/samples/Support13Demos/res/layout/fragment_pager.xml
complete}
The R.layout.fragment_pager_list resource containing each
individual fragment's layout is:
{@sample development/samples/Support13Demos/res/layout/fragment_pager_list.xml
complete} |