public abstract class FragmentRemovePagerAdapter
extends PagerAdapter
PagerAdapter that
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
FragmentStatePagerAdapter.
When using FragmentPagerAdapter the host ViewPager must have a valid ID set.
Subclasses only need to implement getItem(int)
and #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:
| 构造器和说明 |
|---|
FragmentRemovePagerAdapter(FragmentManager fm) |
| 限定符和类型 | 方法和说明 |
|---|---|
void |
destroyItem(android.view.ViewGroup container,
int position,
Object object) |
void |
finishUpdate(android.view.ViewGroup container) |
abstract Fragment |
getItem(int position)
Return the Fragment associated with a specified position.
|
long |
getItemId(int position)
Return a unique identifier for the item at the given position.
|
Object |
instantiateItem(android.view.ViewGroup container,
int position) |
boolean |
isViewFromObject(android.view.View view,
Object object) |
void |
removeAll()
Remove all item
|
void |
restoreState(android.os.Parcelable state,
ClassLoader loader) |
android.os.Parcelable |
saveState() |
void |
setPrimaryItem(android.view.ViewGroup container,
int position,
Object object) |
void |
startUpdate(android.view.ViewGroup container) |
public abstract Fragment getItem(int position)
public void startUpdate(android.view.ViewGroup container)
public Object instantiateItem(android.view.ViewGroup container, int position)
public void destroyItem(android.view.ViewGroup container,
int position,
Object object)
public void setPrimaryItem(android.view.ViewGroup container,
int position,
Object object)
public void finishUpdate(android.view.ViewGroup container)
public boolean isViewFromObject(android.view.View view,
Object object)
public android.os.Parcelable saveState()
public void restoreState(android.os.Parcelable state,
ClassLoader loader)
public long getItemId(int position)
The default implementation returns the given position. Subclasses should override this method if the positions of items can change.
position - Position within this adapterpublic void removeAll()