让我们看看这个例子吧;
//进行数据的添加
///添加一个数据储存 对象 ArrayList<HashMap<String,String>>
ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
HashMap<String,String> map1 = new HashMap<String,String>();
HashMap<String,String> map2 = new HashMap<String,String>();
HashMap<String,String> map3 = new HashMap<String,String>();
///分别添加HashMap对象
map1.put("user_name", "周周");
map1.put("user_ip", "192.168.1.1");
map2.put("user_name", "郭佳");
map2.put("user_ip", "192.168.1.2");
map3.put("user_name", "张立飞");
map3.put("user_ip", "192.168.1.3");
///将这个HashMap对象添加到List里面
list.add(map1);
list.add(map2);
list.add(map3);
/**SimpleAdapter s = new SimpleAdapter();
* 参数:
* 1:当前Content
* 2:数据对象
* 3:这些数据要怎么显示的 布局文件
* 4:String数组
* 5:int数组
*/
SimpleAdapter listAdapter = new SimpleAdapter(this,list, R.layout.user,
new String[]{"user_name","user_ip"},
new int[]{R.id.user_name,R.id.user_ip});
///将这个listAdapter对象添加到Content
setListAdapter(listAdapter);
这个是一个简单的Adapter对象,和ListActivity一起使用;
关于其中的参数我想说的是最后的两个;
new String[] 对象,,user_name 与use_ip都为储存在list数据中的key
new int[] 为布局文件中相应的显示控件(如:R.id.user_name为显示用户名的名字,在布局文件中是一个TextView对像)
分享到:
相关推荐
主要介绍了Android SimpleAdapter使用详解的相关资料,需要的朋友可以参考下
《List控件使用---SimpleAdapter使用详解(一)》博文对应源码,该博文讲解了怎样使用simpleAdapter及派生自BaseAdater的ListView的使用方法,博客地址:...
《 List控件使用---SimpleAdapter使用详解(二)》:实现从本地JSON文件生成listView界面;对应博文地址:http://blog.csdn.net/harvic880925/article/details/17288687
《List控件使用---SimpleAdapter使用详解(一)》对应源码,讲解了listView的使用,博文对应地址:http://blog.csdn.net/harvic880925/article/details/17258789
主要介绍了Android UI:ListView - SimpleAdapter实例详解,SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便,需要的朋友可以参考下
自己编写的,SimpleAdapter简单列子,供初学者参考
SimpleAdapter实现的GalleryDemo
Android UI:ListView — SimpleAdapter SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便。 layout : <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=...
SimpleAdapter BaseAdapter 基本使用
ArrayAdapter和SimpleAdapter是适配器的两种。ListView控件是最常用的控件之一,ListView的经常使用ArrayAdapter和SimpleAdapter来加载数据源。ArrayAdapter(数组适配器)用作展现简单的纯文字列表;SimpleAdapter...
SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.list_item, new String[] { "img", "title", "info" }, new int[] { R.id.img, R.id.title, R.id.info }); lv.setAdapter...
Android SimpleAdapter 列表(ListView)、表格(GridView)
Android的SimpleAdapter的一些简单应用,讲图片和列表结合。
NULL 博文链接:https://thinkgoogle.iteye.com/blog/1313519
simpleAdpter的Android桌面的图标列子,上面一个图片下载文字说明。
ArrayAdapter和simpleAdapter的回顾,好长时间都没有写android了,今天出来溜溜,这个写的是最初的功能。 就是listview。simpleAdapter是左图片右文本、 这个适合初学者玩下。
使用SimpleAdapter创建ListView
关于simpleadapter的各种详细说明,适用于初学者,有详细备注
ListView +SimpleAdapter 实现