Android-SimpleAdapter使用方法

xiaoxiao2021-02-28  120

// [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);

转载请注明原文地址: https://www.6miu.com/read-33380.html

最新回复(0)