SimpleAdapter
有较好的扩充性,可以自定义布局
案例:自带头像的通讯录设置
lv= (ListView) findViewById(R.id.lv); final List list=new ArrayList(); Map map=new HashMap(); map.put("imag",R.mipmap.f1); map.put("name", "微信"); list.add(map); map=new HashMap(); map.put("imag",R.mipmap.f2); map.put("name", "微博"); list.add(map); map=new HashMap(); map.put("imag",R.mipmap.f3); map.put("name", "腾讯"); list.add(map); map=new HashMap(); map.put("imag",R.mipmap.f4); map.put("name", "腾讯网"); list.add(map); map=new HashMap(); map.put("imag",R.mipmap.f1); map.put("name", "微信"); list.add(map); map=new HashMap(); map.put("imag",R.mipmap.f3); map.put("name", "QQ"); list.add(map); map=new HashMap(); map.put("imag",R.mipmap.f2); map.put("name", "微博"); list.add(map); map=new HashMap(); map.put("imag",R.mipmap.f4); map.put("name", "腾讯网"); list.add(map); SimpleAdapter sa=new SimpleAdapter(this,list,R.layout.listview_layout2, new String[]{"imag","name"}, new int[]{R.id.iv,R.id.tv}); lv.setAdapter(sa); lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, View view, int position, long id) { Map map= (Map) list.get(position); Toast.makeText(getBaseContext(),""+map.get("name"),Toast.LENGTH_SHORT).show(); Toast.makeText(getBaseContext(),"点击了"+(position+1)+"行",Toast.LENGTH_SHORT).show(); } }); }总结:
需要和Map连用,来传输对应的键和值
simpleAdapter参数设置
(Context context,List<? extends Map<String,?>> data, int resource,String[] from, int[] to)