Most visited

Recently visited

Added in API level 1

Adapter

public interface Adapter

android.widget.Adapter
Known Indirect Subclasses


适配器对象充当AdapterView与该视图的基础数据之间的桥梁。 适配器提供对数据项的访问。 适配器还负责为数据集中的每个项目制作View

也可以看看:

Summary

Constants

int IGNORE_ITEM_VIEW_TYPE

导致 AdapterView忽略项目视图的项目视图类型。

int NO_SELECTION

Public methods

abstract int getCount()

本适配器所代表的数据集中有多少项目。

abstract Object getItem(int position)

获取与数据集中指定位置关联的数据项。

abstract long getItemId(int position)

获取与列表中指定位置关联的行ID。

abstract int getItemViewType(int position)

获取指定项目将由 getView(int, View, ViewGroup)创建的视图类型。

abstract View getView(int position, View convertView, ViewGroup parent)

获取显示数据集中指定位置的数据的视图。

abstract int getViewTypeCount()

返回将由 getView(int, View, ViewGroup)创建的视图类型的数量。

abstract boolean hasStableIds()

指示项目id在基础数据更改期间是否稳定。

abstract boolean isEmpty()
abstract void registerDataSetObserver(DataSetObserver observer)

注册一个在此适配器使用的数据发生更改时调用的观察者。

abstract void unregisterDataSetObserver(DataSetObserver observer)

通过 registerDataSetObserver(DataSetObserver)取消注册先前已通过此适配器注册的观察员。

Constants

IGNORE_ITEM_VIEW_TYPE

Added in API level 1
int IGNORE_ITEM_VIEW_TYPE

导致AdapterView忽略项目视图的项目视图类型。 例如,如果客户不希望在getView(int, View, ViewGroup)为转换给出特定视图,则可以使用此getView(int, View, ViewGroup)

也可以看看:

常量值:-1(0xffffffff)

NO_SELECTION

Added in API level 1
int NO_SELECTION

常量值:-2147483648(0x80000000)

Public methods

getCount

Added in API level 1
int getCount ()

本适配器所代表的数据集中有多少项目。

Returns
int Count of items.

getItem

Added in API level 1
Object getItem (int position)

获取与数据集中指定位置关联的数据项。

Parameters
position int: Position of the item whose data we want within the adapter's data set.
Returns
Object The data at the specified position.

getItemId

Added in API level 1
long getItemId (int position)

获取与列表中指定位置关联的行ID。

Parameters
position int: The position of the item within the adapter's data set whose row id we want.
Returns
long The id of the item at the specified position.

getItemViewType

Added in API level 1
int getItemViewType (int position)

获取指定项目将由 getView(int, View, ViewGroup)创建的视图类型。

Parameters
position int: The position of the item within the adapter's data set whose view type we want.
Returns
int An integer representing the type of View. Two views should share the same type if one can be converted to the other in getView(int, View, ViewGroup). Note: Integers must be in the range 0 to getViewTypeCount() - 1. IGNORE_ITEM_VIEW_TYPE can also be returned.

也可以看看:

getView

Added in API level 1
View getView (int position, 
                View convertView, 
                ViewGroup parent)

获取显示数据集中指定位置的数据的视图。 您可以手动创建视图或从XML布局文件中对其进行膨胀。 当视图膨胀时,父View(GridView,ListView ...)将应用默认布局参数,除非您使用inflate(int, android.view.ViewGroup, boolean)来指定根视图并防止附加到根。

Parameters
position int: The position of the item within the adapter's data set of the item whose view we want.
convertView View: The old view to reuse, if possible. Note: You should check that this view is non-null and of an appropriate type before using. If it is not possible to convert this view to display the correct data, this method can create a new view. Heterogeneous lists can specify their number of view types, so that this View is always of the right type (see getViewTypeCount() and getItemViewType(int)).
parent ViewGroup: The parent that this view will eventually be attached to
Returns
View A View corresponding to the data at the specified position.

getViewTypeCount

Added in API level 1
int getViewTypeCount ()

返回将由getView(int, View, ViewGroup)创建的视图类型的数量。 每种类型代表一组可以在getView(int, View, ViewGroup)转换的getView(int, View, ViewGroup) 如果适配器始终为所有项返回相同类型的视图,则此方法应返回1。

只有在适配器设置为 AdapterView时才会调用此方法。

Returns
int The number of types of Views that will be created by this adapter

hasStableIds

Added in API level 1
boolean hasStableIds ()

指示项目id在基础数据更改期间是否稳定。

Returns
boolean True if the same id always refers to the same object.

isEmpty

Added in API level 1
boolean isEmpty ()

Returns
boolean true if this adapter doesn't contain any data. This is used to determine whether the empty view should be displayed. A typical implementation will return getCount() == 0 but since getCount() includes the headers and footers, specialized adapters might want a different behavior.

registerDataSetObserver

Added in API level 1
void registerDataSetObserver (DataSetObserver observer)

注册一个在此适配器使用的数据发生更改时调用的观察者。

Parameters
observer DataSetObserver: the object that gets notified when the data set changes.

unregisterDataSetObserver

Added in API level 1
void unregisterDataSetObserver (DataSetObserver observer)

通过 registerDataSetObserver(DataSetObserver)取消注册先前已通过此适配器注册的观察员。

Parameters
observer DataSetObserver: the object to unregister.

Hooray!