其他两种绑定ListView数据的方式
2015-10-29 00:20
357 查看
ArrayAdapter
ListView mListView = (ListView) findViewById(R.id.listview);
String[] textArray = {"功能1","功能2","功能3","功能4","功能5","功能6","功能7","功能8"};
/*
* 定义数据适配器
* android.R.layout.simple_list_item_1 Listview的子条目显示的布局的id
* textArray 显示在ListView列表中的数据
*/
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
textArray);
mListView.setAdapter(adapter);
SimpleAdapter
ListView mListView = (ListView) findViewById(R.id.listview);
List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "张三1");
map.put("icon", R.drawable.f007);
data.add(map);
map = new HashMap<String, Object>();
map.put("name", "张三2");
map.put("icon", R.drawable.f007);
data.add(map);
map = new HashMap<String, Object>();
map.put("name", "张三3");
map.put("icon", R.drawable.f007);
data.add(map);
map = new HashMap<String, Object>();
map.put("name", "张三4");
map.put("icon", R.drawable.f007);
data.add(map);
map = new HashMap<String, Object>();
map.put("name", "张三5");
map.put("icon", R.drawable.f007);
data.add(map);
SimpleAdapter adapter = new SimpleAdapter(
this, // 上下文
data, // listView绑定的数据
R.layout.listview_item, // listview的子条目的布局的id
new String[]{"name", "icon"}, // data数据中的map集合里的key
new int[]{R.id.tv_name, R.id.iv_icon}); // resource 中的id
mListView.setAdapter(adapter);
ListView mListView = (ListView) findViewById(R.id.listview);
String[] textArray = {"功能1","功能2","功能3","功能4","功能5","功能6","功能7","功能8"};
/*
* 定义数据适配器
* android.R.layout.simple_list_item_1 Listview的子条目显示的布局的id
* textArray 显示在ListView列表中的数据
*/
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,
textArray);
mListView.setAdapter(adapter);
SimpleAdapter
ListView mListView = (ListView) findViewById(R.id.listview);
List<Map<String, Object>> data = new ArrayList<Map<String,Object>>();
Map<String, Object> map = new HashMap<String, Object>();
map.put("name", "张三1");
map.put("icon", R.drawable.f007);
data.add(map);
map = new HashMap<String, Object>();
map.put("name", "张三2");
map.put("icon", R.drawable.f007);
data.add(map);
map = new HashMap<String, Object>();
map.put("name", "张三3");
map.put("icon", R.drawable.f007);
data.add(map);
map = new HashMap<String, Object>();
map.put("name", "张三4");
map.put("icon", R.drawable.f007);
data.add(map);
map = new HashMap<String, Object>();
map.put("name", "张三5");
map.put("icon", R.drawable.f007);
data.add(map);
SimpleAdapter adapter = new SimpleAdapter(
this, // 上下文
data, // listView绑定的数据
R.layout.listview_item, // listview的子条目的布局的id
new String[]{"name", "icon"}, // data数据中的map集合里的key
new int[]{R.id.tv_name, R.id.iv_icon}); // resource 中的id
mListView.setAdapter(adapter);
相关文章推荐
- JDK动态代理和Cglib的动态代理
- LeetCode——Unique Path
- 关于TableViewCell的重用机制
- Peeking Iterator
- 手速练习
- js中回调函数的运用
- tomcat pipline设计模式
- iOS性能优化那些事
- Javascript-history.go()和history.back()的用法和区别
- 软件测试的范围
- Android Activity启动模式分析
- 如何防止dll注入
- 扩展方法
- [置顶] Test Top
- 获取选中cell的大小位置
- easyui-combobox---ajax获取数据库JSON数据,实现搜索框实时显示模糊搜索结果
- 3、Swift变量、常量、函数、类以及扩展类的使用
- 项目冲刺,第一天
- UIColor的RGB定义颜色(灰色)
- Tomcat学习之Request/Response封装