public class SimpleAdapter
extends BaseAdapter
implements Filterable, ThemedSpinnerAdapter
java.lang.Object | ||
↳ | android.widget.BaseAdapter | |
↳ | android.widget.SimpleAdapter |
一个简单的适配器,可将静态数据映射到XML文件中定义的视图。 您可以将支持列表的数据指定为Maps的ArrayList。 ArrayList中的每个条目都对应于列表中的一行。 地图包含每行的数据。 您还可以指定一个XML文件,该文件定义用于显示行的视图以及从Map中的键到特定视图的映射。 将数据绑定到视图分两个阶段进行。 首先,如果SimpleAdapter.ViewBinder
可用,则调用setViewValue(android.view.View, Object, String)
。 如果返回值为true,则发生绑定。 如果返回值为false,则按顺序尝试以下视图:
setViewText(TextView, String)
is invoked. setViewImage(ImageView, int)
or setViewImage(ImageView, String)
is invoked. IllegalStateException
is thrown.
Nested classes |
|
---|---|
interface |
SimpleAdapter.ViewBinder SimpleAdapter的外部客户端可以使用此类将值绑定到视图。 |
Inherited constants |
---|
From interface android.widget.Adapter
|
Public constructors |
|
---|---|
SimpleAdapter(Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to) 构造函数 |
Public methods |
|
---|---|
int |
getCount() 本适配器所代表的数据集中有多少项目。 |
View |
getDropDownView(int position, View convertView, ViewGroup parent) |
Resources.Theme |
getDropDownViewTheme() 返回以前通过调用 |
Filter |
getFilter() 返回可用于使用过滤模式约束数据的过滤器。 |
Object |
getItem(int position) 获取与数据集中指定位置关联的数据项。 |
long |
getItemId(int position) 获取与列表中指定位置关联的行ID。 |
View |
getView(int position, View convertView, ViewGroup parent) 获取显示数据集中指定位置的数据的视图。 |
SimpleAdapter.ViewBinder |
getViewBinder() 返回用于将数据绑定到视图的 |
void |
setDropDownViewResource(int resource) 设置布局资源以创建下拉视图。 |
void |
setDropDownViewTheme(Resources.Theme theme) 设置 |
void |
setViewBinder(SimpleAdapter.ViewBinder viewBinder) 设置用于将数据绑定到视图的联编程序。 |
void |
setViewImage(ImageView v, int value) 由bindView()调用以设置ImageView的图像,但前提是没有现有的ViewBinder或现有的ViewBinder无法处理与ImageView的绑定。 |
void |
setViewImage(ImageView v, String value) 由bindView()调用以设置ImageView的图像,但前提是没有现有的ViewBinder或现有的ViewBinder无法处理与ImageView的绑定。 |
void |
setViewText(TextView v, String text) 只有在没有现有的ViewBinder或现有ViewBinder无法处理与TextView的绑定时,才由bindView()调用以设置TextView的文本。 |
Inherited methods |
|
---|---|
From class android.widget.BaseAdapter
|
|
From class java.lang.Object
|
|
From interface android.widget.ListAdapter
|
|
From interface android.widget.SpinnerAdapter
|
|
From interface android.widget.Filterable
|
|
From interface android.widget.ThemedSpinnerAdapter
|
|
From interface android.widget.Adapter
|
SimpleAdapter (Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
构造函数
Parameters | |
---|---|
context |
Context : The context where the View associated with this SimpleAdapter is running |
data |
List : A List of Maps. Each entry in the List corresponds to one row in the list. The Maps contain the data for each row, and should include all the entries specified in "from" |
resource |
int : Resource identifier of a view layout that defines the views for this list item. The layout file should include at least those named views defined in "to" |
from |
String : A list of column names that will be added to the Map associated with each item. |
to |
int : The views that should display column in the "from" parameter. These should all be TextViews. The first N views in this list are given the values of the first N columns in the from parameter. |
View getDropDownView (int position, View convertView, ViewGroup parent)
获取 View
,它在下拉式弹出 View
中显示数据集中指定位置的数据。
Parameters | |
---|---|
position |
int : index 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. |
parent |
ViewGroup : the parent that this view will eventually be attached to |
Returns | |
---|---|
View |
a View corresponding to the data at the specified position. |
Resources.Theme getDropDownViewTheme ()
返回以前通过调用 setDropDownViewTheme(Theme)
设置的值。
Returns | |
---|---|
Resources.Theme |
the Resources.Theme against which drop-down views are inflated, or null if one has not been explicitly set |
Filter getFilter ()
返回可用于使用过滤模式约束数据的过滤器。
此方法通常由 Adapter
类实现。
Returns | |
---|---|
Filter |
a filter used to constrain data |
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. |
也可以看看:
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. |
也可以看看:
View getView (int position, View convertView, ViewGroup parent)
获取显示数据集中指定位置的数据的视图。 您可以手动创建视图或从XML布局文件中对其进行膨胀。 当视图膨胀时,父视图(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. |
SimpleAdapter.ViewBinder getViewBinder ()
返回用于将数据绑定到视图的 SimpleAdapter.ViewBinder
。
Returns | |
---|---|
SimpleAdapter.ViewBinder |
a ViewBinder or null if the binder does not exist |
void setDropDownViewResource (int resource)
设置布局资源以创建下拉视图。
Parameters | |
---|---|
resource |
int : the layout resource defining the drop down views |
void setDropDownViewTheme (Resources.Theme theme)
设置 Resources.Theme
的下拉视图充气。
默认情况下,下拉视图会根据传递给适配器构造函数的 Context
的主题进行膨胀。
Parameters | |
---|---|
theme |
Resources.Theme : the theme against which to inflate drop-down views or null to use the theme from the adapter's context |
void setViewBinder (SimpleAdapter.ViewBinder viewBinder)
设置用于将数据绑定到视图的联编程序。
Parameters | |
---|---|
viewBinder |
SimpleAdapter.ViewBinder : the binder used to bind data to views, can be null to remove the existing binder |
也可以看看:
void setViewImage (ImageView v, int value)
由bindView()调用以设置ImageView的图像,但前提是没有现有的ViewBinder或现有的ViewBinder无法处理与ImageView的绑定。 如果提供的数据是int或Integer,则调用此方法而不是setViewImage(ImageView, String)
。
Parameters | |
---|---|
v |
ImageView : ImageView to receive an image |
value |
int : the value retrieved from the data set |
void setViewImage (ImageView v, String value)
由bindView()调用以设置ImageView的图像,但前提是没有现有的ViewBinder或现有的ViewBinder无法处理与ImageView的绑定。 默认情况下,该值将被视为图像资源。 如果该值不能用作图像资源,则该值将用作图像Uri。 如果提供的数据不是int或Integer,则调用此方法而不是setViewImage(ImageView, int)
。
Parameters | |
---|---|
v |
ImageView : ImageView to receive an image |
value |
String : the value retrieved from the data set |
也可以看看:
void setViewText (TextView v, String text)
只有在没有现有的ViewBinder或现有ViewBinder无法处理与TextView的绑定时,才由bindView()调用以设置TextView的文本。
Parameters | |
---|---|
v |
TextView : TextView to receive text |
text |
String : the text to be set for the TextView |