构造函数SimpleAdapter()

作为一个初学者,对于Java 和 Android都是,有很多地方先需要记住的,然后在使用中慢慢体会,理解。现在要记住的就是构造方法SimpleAdapter()的用法。看文档介绍如下:

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

Constructor

Parameters
contextThe context where the View associated with this SimpleAdapter is running
dataA 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"
resourceResource 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"
fromA list of column names that will be added to the Map associated with each item.
toThe 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[ ]是数组。

转载于:https://www.cnblogs.com/haiming/archive/2012/08/10/2631303.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值