当列表只要一列的时候使用
String[] objects = new String[]{ "小小1", "小小2", "小小3" }; ListView lv = (ListView) findViewById(R.id.lv); lv.setAdapter(new ArrayAdapter<String>(this, R.layout.item_listview, R.id.tv_name, objects));
当列表有多列的时候使用
ListView lv = (ListView) findViewById(R.id.lv); //集合中每个元素都包含ListView条目需要的所有数据,该案例中每个条目需要一个字符串和一个整型,所以使用一个map来封装这两种数据 List<Map<String, Object>> data = new ArrayList<Map<String,Object>>(); Map<String, Object> map1 = new HashMap<String, Object>(); map1.put("photo", R.drawable.photo1); map1.put("name", "小小1"); data.add(map1); Map<String, Object> map2 = new HashMap<String, Object>(); map2.put("photo", R.drawable.photo2); map2.put("name", "小小2"); data.add(map2); Map<String, Object> map3 = new HashMap<String, Object>(); map3.put("photo", R.drawable.photo3); map3.put("name", "小小3"); data.add(map3); lv.setAdapter(new SimpleAdapter(this, data, R.layout.item_listview, new String[]{"photo", "name"}, new int[]{R.id.iv_photo, R.id.tv_name}))