`
kanwoerzi
  • 浏览: 1645246 次
文章分类
社区版块
存档分类
最新评论

Android控件开发之四----ListView(3)

 
阅读更多

下面介绍下SimpleAdapter的相关知识

以下是官方网上对SimpleAdapter的介绍:

An easy adapter to map static data to views defined in an XML file. You can specify the data backing the list as an ArrayList of Maps. Each entry in the ArrayList corresponds to one row in the list. The Maps contain the data for each row. You also specify an XML file that defines the views used to display the row, and a mapping from keys in the Map to specific views.

Binding data to views occurs in two phases.

First, if a SimpleAdapter.ViewBinder is available, setViewValue(android.view.View, Object, String) is invoked.

If the returned value is true, binding has occurred.

If the returned value is false, the following views are then tried in order:
(1)A view that implements Checkable (e.g. CheckBox). The expected bind value is a boolean.
(2)TextView. The expected bind value is a string and setViewText(TextView, String) is invoked.
(3)ImageView. The expected bind value is a resource id or a string and setViewImage(ImageView, int) or setViewImage(ImageView, String) is invoked.
If no appropriate binding can be found, an IllegalStateException is thrown.

(大概中文解释:适配器,将静态数据映射到在xml文件中定义的视图上,指定数据列表。每个ArrayList中得一项对应在ListView中的一行。你能自定一个Layout布局文件通过关键字映射来显示数据。

绑定数据分为两个阶段:

首先,如果一个SimpleAdapter.ViewBinder是有效的,setViewValue(android.view.View, Object, String)将被调用;

否则,如果返回失败,则会尝试以下的几个步骤。。。。。)


上代码

注2:

public SimpleAdapter (Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)

参数

context 关联SimpleAdapter运行着的视图的上下文。
data 一个Map的列表。在列表中的每个条目对应列表中的一行,应该包含所有在from中指定的条目
resource 一个定义列表项目的视图布局的资源唯一标识。布局文件将至少应包含哪些在to中定义了的名称。
from 一个将被添加到Map上关联每一个项目的列名称的列表
to 应该在参数from显示列的视图。这些应该全是TextView。在列表中最初的N视图是从参数from中最初的N列获取的值。

注3:

显示数据,通过getDropDownView获取要显示的数据。。。。


list_item.xml(ListView每个Item显示布局)


有问题请留言。。。谢谢。。。

联系方式:ligexiao@gmail.com

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics