除了基本的Baseadapter之外还有两个adapter也是经常使用的,一个是simpleadapter,另一个是Arrayadapter。
Arrayadapter的使用非常简单,几行代码就可以搞定:
String mString[] = {"ww","小明","yy"};
ListView mListView = (ListView) findViewById(R.id.listid);
ArrayAdapter<String> mAdapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
mString);
mListView.setAdapter(mAdapter);
SimpleAdapter稍稍复杂点
List<Map<String,Object>> mList = new ArrayList<Map<String,Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "xiaoming");
map.put("image", R.drawable.ic_launcher);
mList.add(map);
map = new HashMap<String, Object>();
map.put("name", "xiaoming");
map.put("image", R.drawable.ic_launcher);
mList.add(map);
// from data 中map的key. to view中对应的id。 resource: 表示加载的xml文件布局
SimpleAdapter mAdapter = new SimpleAdapter(this, mList, R.layout.listxml,
new String[]{"name","image"},
new int[]{R.id.textview,R.id.imageview1});
ListView mListView = (ListView) findViewById(R.id.listid);
mListView.setAdapter(mAdapter);
这里是可以加载xml布局文件的