public abstract class BaseFragmentPagerAdapter extends PagerAdapter
FragmentPagerAdapter
with four very important modifications.
makeFragmentName(int, int)
is declared "protected"
in our class. We need to be able to re-define the fragment's name according to data
only available to sub-classes.isViewFromObject(View, Object)
has been reimplemented to search
the entire view hierarchy for the given view.destroyItem(View, int, Object)
, the fragment is detached and
added to a cache. If the fragment is evicted from the cache, it will be deleted.
An album may contain thousands of photos and we want to avoid having thousands of
fragments.POSITION_NONE, POSITION_UNCHANGED
Constructor and Description |
---|
BaseFragmentPagerAdapter(FragmentManager fm) |
Modifier and Type | Method and Description |
---|---|
void |
destroyItem(View container,
int position,
Object object)
Remove a page for the given position.
|
void |
finishUpdate(View 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(View container,
int position)
Create the page for the given position.
|
boolean |
isViewFromObject(View view,
Object object)
Determines whether a page View is associated with a specific key object
as returned by
PagerAdapter.instantiateItem(ViewGroup, int) . |
protected String |
makeFragmentName(int viewId,
int index)
Creates a name for the fragment
|
void |
restoreState(Parcelable state,
ClassLoader loader)
Restore any instance state associated with this adapter and its pages
that was previously saved by
PagerAdapter.saveState() . |
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(View 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(View container)
Called when a change in the shown pages is going to start being made.
|
destroyItem, finishUpdate, getCount, getItemPosition, getPageTitle, getPageWidth, instantiateItem, notifyDataSetChanged, registerDataSetObserver, setPrimaryItem, startUpdate, unregisterDataSetObserver
public BaseFragmentPagerAdapter(FragmentManager fm)
public abstract Fragment getItem(int position)
public void startUpdate(View container)
PagerAdapter
startUpdate
in class PagerAdapter
container
- The containing View which is displaying this adapter's
page views.public Object instantiateItem(View container, int position)
PagerAdapter
PagerAdapter.finishUpdate(ViewGroup)
.instantiateItem
in class PagerAdapter
container
- The containing View in which the page will be shown.position
- The page position to be instantiated.public void destroyItem(View container, int position, Object object)
PagerAdapter
PagerAdapter.finishUpdate(View)
.destroyItem
in class PagerAdapter
container
- 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(View container, int position, Object object)
PagerAdapter
setPrimaryItem
in class PagerAdapter
container
- 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(View container)
PagerAdapter
finishUpdate
in class PagerAdapter
container
- The containing View which is displaying this adapter's
page views.public boolean isViewFromObject(View view, Object object)
PagerAdapter
PagerAdapter.instantiateItem(ViewGroup, int)
. This method is
required for a PagerAdapter to function properly.isViewFromObject
in class PagerAdapter
view
- Page View to check for association with object
object
- Object to check for association with view
view
is associated with the key object object
public Parcelable saveState()
PagerAdapter
saveState
in class PagerAdapter
public void restoreState(Parcelable state, ClassLoader loader)
PagerAdapter
PagerAdapter.saveState()
.restoreState
in class PagerAdapter
state
- State previously saved by a call to PagerAdapter.saveState()
loader
- A ClassLoader that should be used to instantiate any restored objectsprotected String makeFragmentName(int viewId, int index)