public abstract class FragmentPagerAdapter
extends PagerAdapter
PagerAdapter implementation that represents each page as a Fragment that is
persistently kept in the fragment manager as long as a user can return to the page.
This version of the pager adapter 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.
Note, that when using FragmentPagerAdapter, the host ViewPager must have a valid ID set, otherwise this adapter implementation will throw an exception.
The inheritance hierarchies only need to implement getItem(int) and
#getCount() to become a fully working adapters.
| Modifier and Type | Field and Description |
|---|---|
static int |
NO_POSITION
Constant used to identify unspecified position.
|
| Constructor and Description |
|---|
FragmentPagerAdapter(FragmentManager fragmentManager)
Creates a new instance of FragmentPagerAdapter with the specified fragmentManager.
|
| Modifier and Type | Method and Description |
|---|---|
void |
destroyItem(android.view.ViewGroup container,
int position,
java.lang.Object object) |
void |
finishUpdate(android.view.ViewGroup container) |
abstract Fragment |
getItem(int position)
Instantiates a new
Fragment associated with the specified position. |
long |
getItemId(int position)
Returns a unique identifier for the item at the specified position.
|
Fragment |
getPrimaryFragment()
Returns the fragment instance that has been set as primary item via
setPrimaryItem(ViewGroup, int, Object). |
int |
getPrimaryPosition()
Returns position of the current primary item.
|
java.lang.Object |
instantiateItem(android.view.ViewGroup container,
int position) |
boolean |
isViewFromObject(android.view.View view,
java.lang.Object object) |
protected java.lang.String |
makeItemTag(int containerId,
long itemId)
Makes a tag for an item with the given itemId.
|
protected void |
setMakeItemTags(boolean makeItemTags)
Sets a boolean flag indicating whether this pager adapter should make tags for its items or
not.
|
void |
setPrimaryItem(android.view.ViewGroup container,
int position,
java.lang.Object object) |
void |
startUpdate(android.view.ViewGroup container) |
public static final int NO_POSITION
public FragmentPagerAdapter(FragmentManager fragmentManager)
fragmentManager - The manager used to manage fragments provided by the pager adapter.public void startUpdate(android.view.ViewGroup container)
public java.lang.Object instantiateItem(android.view.ViewGroup container,
int position)
protected final void setMakeItemTags(boolean makeItemTags)
This feature is by default enabled.
makeItemTags - True to enable making of item tags, false otherwise.makeItemTag(int, long)protected java.lang.String makeItemTag(int containerId,
long itemId)
By default making of item tags is enabled and the default implementation makes tag in the following format:
"android:pager:CONTAINER_ID:ITEM_ID"This feature may be enabled/disabled via
setMakeItemTags(boolean).containerId - Id of the associated view pager container.itemId - Id of the item for which to create its corresponding tag.null if this adapter does not create tags for its items.public long getItemId(int position)
The default implementation returns the given position. The inheritance hierarchies should override this method if the positions of items can change.
position - Position from the range of size of this this adapter.public abstract Fragment getItem(int position)
Fragment associated with the specified position.instantiateItem(ViewGroup, int)public void setPrimaryItem(android.view.ViewGroup container,
int position,
java.lang.Object object)
public Fragment getPrimaryFragment()
setPrimaryItem(ViewGroup, int, Object).null if no primary item has been set yet.getPrimaryPosition()public int getPrimaryPosition()
NO_POSITION if no primary item has been specified yet.getPrimaryFragment(),
setPrimaryItem(ViewGroup, int, Object)public boolean isViewFromObject(android.view.View view,
java.lang.Object object)
public void destroyItem(android.view.ViewGroup container,
int position,
java.lang.Object object)
public void finishUpdate(android.view.ViewGroup container)