Android-SimpleAdapter使用方法

        // [1] 找到控件
        ListView lv = (ListView) findViewById(R.id.lv);

        // [1.1] 准备listview要显示的数据
        List<Map<String, String>> data = new ArrayList<>();

        Map<String, String> map1 = new HashMap<>();
        map1.put("name", "张飞");
        map1.put("phone", "13888888888");

        Map<String, String> map2 = new HashMap<>();
        map2.put("name", "赵云");
        map2.put("phone", "110");

        Map<String, String> map3 = new HashMap<>();
        map3.put("name", "貂蝉");
        map3.put("phone", "13888882223");

        Map<String, String> map4 = new HashMap<>();
        map4.put("name", "诸葛亮");
        map4.put("phone", "13888881234");

        // [1.2] 把map假如到集合中
        data.add(map1);
        data.add(map2);
        data.add(map3);
        data.add(map4);

        // [2] 设置数据适配器

        // form map集合的键
        SimpleAdapter adapter = new SimpleAdapter(getApplicationContext(), data, R.layout.item,
                new String[]{"name", "phone"}, new int[]{R.id.tv_name, R.id.tv_phone});

        lv.setAdapter(adapter);

1

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值