作为一个初学者,对于Java 和 Android都是,有很多地方先需要记住的,然后在使用中慢慢体会,理解。现在要记住的就是构造方法SimpleAdapter()的用法。看文档介绍如下:
public SimpleAdapter (Context context, List<? extends Map<String, ?>> data, int resource, String[] from, int[] to)
Since: API Level 1
Constructor
Parameters
context | The context where the View associated with this SimpleAdapter is running |
---|---|
data | 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 | 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 | A list of column names that will be added to the Map associated with each item. |
to | 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. |
Context :一般使用this。
data:是个列表,这个列表中包含的应该是Map,在代码中,可以如下使用:
List<Map<String,Object>> data = new ArrayList<Map<String,Object>>();
Map<String,Object> map = new HashMap<String,Object>();
map.put(...);
data.add(map);
这样就可以使用这个data作为参数了。
resource:是用来填充ListView的布局文件,比如我们可以在item.xml定义如何填充ListView的一项,其实Listview中的每一项都是这么填充。
还要注意最后两个参数是String[ ],int[ ]是数组。