public abstract class FragmentGridPagerAdapter
extends GridPagerAdapter
| java.lang.Object | ||
| ↳ | android.support.wearable.view.GridPagerAdapter | |
| ↳ | android.support.wearable.view.FragmentGridPagerAdapter | |
GridPagerAdapter的一个实现,它将每个页面表示为 Fragment 。
最小实现只需要抽象方法: getRowCount() , getColumnCount(int) , getFragment(int, int) 。
如果对数据进行了任何更改, notifyDataSetChanged()必须调用 notifyDataSetChanged()以通知适配器该更改,以便它可以反映在视图中。
如果要插入或删除数据页面,可以通过实施 getFragmentId(int, int)来提高性能,以根据内容为每个项目提供稳定的ID。
Inherited constants |
|---|
android.support.wearable.view.GridPagerAdapter
|
Inherited fields |
|---|
android.support.wearable.view.GridPagerAdapter
|
Public constructors |
|
|---|---|
FragmentGridPagerAdapter(FragmentManager fm) |
|
Public methods |
|
|---|---|
void |
destroyItem(ViewGroup container, int row, int column, Object object) 移除给定位置的页面。 |
Fragment |
findExistingFragment(int row, int column) |
void |
finishUpdate(ViewGroup container) 在所示页面中的更改完成时调用。 |
Drawable |
getBackgroundForPage(int row, int column) 提供内容作为特定页面的背景显示。 |
abstract Fragment |
getFragment(int row, int column) 返回指定行号和列号的 |
final Drawable |
getFragmentBackground(int row, int column) 返回实现 |
long |
getFragmentId(int row, int column) 返回给定行/列位置的 |
Fragment |
instantiateItem(ViewGroup container, int row, int column) 为给定位置创建页面。 |
boolean |
isViewFromObject(View view, Object object) 确定页面视图是否与 |
Protected methods |
|
|---|---|
void |
applyItemPosition(Object object, Point position) 在 |
void |
removeFragment(Fragment fragment, FragmentTransaction transaction) |
void |
restoreFragment(Fragment fragment, FragmentTransaction transaction) |
Inherited methods |
|
|---|---|
android.support.wearable.view.GridPagerAdapter
|
|
java.lang.Object
|
|
FragmentGridPagerAdapter (FragmentManager fm)
| Parameters | |
|---|---|
fm |
FragmentManager
|
void destroyItem (ViewGroup container,
int row,
int column,
Object object)
移除给定位置的页面。 适配器负责从容器中移除视图,但它只能确保在从finishUpdate(ViewGroup)返回时完成finishUpdate(ViewGroup) 。
| Parameters | |
|---|---|
container |
ViewGroup: The containing View from which the page will be removed. |
row |
int: the row to be destroyed |
column |
int: the column within the row to be destroyed |
object |
Object: The same object that was returned by instantiateItem(ViewGroup, int, int). |
Fragment findExistingFragment (int row,
int column)
| Parameters | |
|---|---|
row |
int
|
column |
int
|
| Returns | |
|---|---|
Fragment |
|
void finishUpdate (ViewGroup container)
在所示页面中的更改完成时调用。 此时,您必须确保所有页面实际上已根据需要添加或从容器中移除。
| Parameters | |
|---|---|
container |
ViewGroup: The containing View which is displaying this adapter's page views |
Drawable getBackgroundForPage (int row,
int column)
提供内容作为特定页面的背景显示。
返回值BACKGROUND_NONE表示没有页面特定的背景。 并应使用行背景(如果有的话)。
这个实现只是返回 getFragmentBackground(int, int)的结果。
| Parameters | |
|---|---|
row |
int: the row of the page |
column |
int: the column of the page |
| Returns | |
|---|---|
Drawable |
the background for the given page or BACKGROUND_NONE |
Fragment getFragment (int row,
int column)
在指定的行号和列号处返回 Fragment 。
只有在对数据集没有进行结构性改变时,或者如果重写 getFragmentId(int, int)每个位置上的每个项目提供稳定的标识符,则片段实例可以被存储和重用,否则结果是未定义的。
| Parameters | |
|---|---|
row |
int: the row of the position |
column |
int: the column of the position |
| Returns | |
|---|---|
Fragment |
|
Drawable getFragmentBackground (int row,
int column)
返回实现 GridPageOptions Fragments的背景。
| Parameters | |
|---|---|
row |
int: the row of the fragment |
column |
int: the column of the fragment |
| Returns | |
|---|---|
Drawable |
the background drawable or BACKGROUND_NONE if the fragment does not implement GridPageOptions |
long getFragmentId (int row,
int column)
返回给定行/列位置的 Fragment的唯一标识符。
默认实现根据位置返回一个固定的数字。 如果项目的位置可以更改,子类应该覆盖此方法。
| Parameters | |
|---|---|
row |
int: the row that this item is at |
column |
int: the column within this row that the item is at |
| Returns | |
|---|---|
long |
Unique identifier for the item at position |
Fragment instantiateItem (ViewGroup container,
int row,
int column)
为给定位置创建页面。 适配器负责将视图添加到此处给出的容器中,但它只能确保在从finishUpdate(ViewGroup)返回时完成此操作
| Parameters | |
|---|---|
container |
ViewGroup: containing View in which the page will be shown |
row |
int: the row to be instantiated |
column |
int: the column within the row to be instantiated |
| Returns | |
|---|---|
Fragment |
a an object representing the new page |
boolean isViewFromObject (View view,
Object object)
确定页面视图是否与instantiateItem(ViewGroup, int, int)返回的特定键对象相关联。 这个方法对于PagerAdapter正常运行是必需的。
| Parameters | |
|---|---|
view |
View: Page View to check for association with object |
object |
Object: Object to check for association with view |
| Returns | |
|---|---|
boolean |
true if view is associated with the key object object |
void applyItemPosition (Object object,
Point position)
在 getItemPosition(Object)之后 getItemPosition(Object)以允许超类更新他们的内部簿记,如果子类已被覆盖 getItemPosition(Object) 。
| Parameters | |
|---|---|
object |
Object: Object representing the item passed to getItemPosition(Object). |
position |
Point: position which was returned from getItemPosition(Object). |
void removeFragment (Fragment fragment,
FragmentTransaction transaction)
| Parameters | |
|---|---|
fragment |
Fragment
|
transaction |
FragmentTransaction
|
void restoreFragment (Fragment fragment,
FragmentTransaction transaction)
| Parameters | |
|---|---|
fragment |
Fragment
|
transaction |
FragmentTransaction
|