android-PagerAdapter

public abstract class

PagerAdapter

extends Object
java.lang.Object
   ↳ android.support.v4.view.PagerAdapter
已知直接子類

類概述


Base class providing the adapter to populate pages inside of a ViewPager. You will most likely want to use a more specific implementation of this, such asFragmentPagerAdapter or FragmentStatePagerAdapter.

When you implement a PagerAdapter, you must override the following methods at minimum:

PagerAdapter is more general than the adapters used for AdapterViews. Instead of providing a View recycling mechanism directly ViewPager uses callbacks to indicate the steps taken during an update. A PagerAdapter may implement a form of View recycling if desired or use a more sophisticated method of managing page Views such as Fragment transactions where each page is represented by its own Fragment.

ViewPager associates each page with a key Object instead of working with Views directly. This key is used to track and uniquely identify a given page independent of its position in the adapter. A call to the PagerAdapter method startUpdate(ViewGroup) indicates that the contents of the ViewPager are about to change. One or more calls to instantiateItem(ViewGroup, int) and/or destroyItem(ViewGroup, int, Object) will follow, and the end of an update will be signaled by a call tofinishUpdate(ViewGroup). By the time finishUpdate returns the views associated with the key objects returned by instantiateItem should be added to the parent ViewGroup passed to these methods and the views associated with the keys passed to destroyItem should be removed. The method isViewFromObject(View, Object)identifies whether a page View is associated with a given key object.

A very simple PagerAdapter may choose to use the page Views themselves as key objects, returning them from instantiateItem(ViewGroup, int) after creation and adding them to the parent ViewGroup. A matching destroyItem(ViewGroup, int, Object) implementation would remove the View from the parent ViewGroup andisViewFromObject(View, Object) could be implemented as return view == object;.

PagerAdapter supports data set changes. Data set changes must occur on the main thread and must end with a call to notifyDataSetChanged() similar to AdapterView adapters derived from BaseAdapter. A data set change may involve pages being added, removed, or changing position. The ViewPager will keep the current page active provided the adapter implements the method getItemPosition(Object).

概述


常量
int POSITION_NONE  
int POSITION_UNCHANGED  
公有構造函數
PagerAdapter()
公有方法
void destroyItem(ViewGroup container, int position, Object object)
Remove a page for the given position.
void destroyItem(View container, int position, Object object)
該 method 從 API 級別 開始已經廢棄。 Use destroyItem(ViewGroup, int, Object)
void finishUpdate(View container)
該 method 從 API 級別 開始已經廢棄。 Use finishUpdate(ViewGroup)
void finishUpdate(ViewGroup container)
Called when the a change in the shown pages has been completed.
abstract int getCount()
Return the number of views available.
int getItemPosition(Object object)
Called when the host view is attempting to determine if an item's position has changed.
CharSequence getPageTitle(int position)
This method may be called by the ViewPager to obtain a title string to describe the specified page.
float getPageWidth(int position)
Returns the proportional width of a given page as a percentage of the ViewPager's measured width from (0.f-1.f]
Object instantiateItem(ViewGroup container, int position)
Create the page for the given position.
Object instantiateItem(View container, int position)
該 method 從 API 級別 開始已經廢棄。 Use instantiateItem(ViewGroup, int)
abstract boolean isViewFromObject(View view, Object object)
Determines whether a page View is associated with a specific key object as returned by instantiateItem(ViewGroup, int).
void notifyDataSetChanged()
This method should be called by the application if the data backing this adapter has changed and associated views should update.
void registerDataSetObserver(DataSetObserver observer)
Register an observer to receive callbacks related to the adapter's data changing.
void restoreState(Parcelable state, ClassLoader loader)
Restore any instance state associated with this adapter and its pages that was previously saved by 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)
該 method 從 API 級別 開始已經廢棄。 Use setPrimaryItem(ViewGroup, int, Object)
void setPrimaryItem(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(View container)
該 method 從 API 級別 開始已經廢棄。 Use startUpdate(ViewGroup)
void startUpdate(ViewGroup container)
Called when a change in the shown pages is going to start being made.
void unregisterDataSetObserver(DataSetObserver observer)
Unregister an observer from callbacks related to the adapter's data changing.
[展開]
繼承方法
 From class java.lang.Object

常量


public static final int POSITION_NONE

常量值: -2 (0xfffffffe)

public static final int POSITION_UNCHANGED

常量值: -1 (0xffffffff)
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章