SimpleAdapter与ListView

动态刷新ListView数据:[url]http://panyongzheng.iteye.com/admin/blogs/1453777[/url]

使用SimpleAdapter:[url]http://www.cnblogs.com/game-over/archive/2010/06/25/1765544.html[/url]
使用BaseAdapter:[url]http://blog.csdn.net/chenzheng_java/article/details/6202586[/url], [color=red]思维很不错[/color]。

listviewdemo2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<Button
android:id="@+id/listView2_bt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="返回" />

<ListView
android:id="@+id/listView2"
android:background="#FFFFFFFF"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>


用于装载到ListView的xml
listviewdemo2_sub.xml
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >

<ImageView
android:id="@+id/img"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

<TextView
android:id="@+id/title"
android:layout_width="214dp"
android:layout_height="40dp"
android:layout_x="92dp"
android:layout_y="2dp"
android:background="#FFFFFFFF"
android:textSize="15dp" />
<TextView
android:id="@+id/info"
android:layout_width="214dp"
android:layout_height="wrap_content"
android:layout_x="92dp"
android:layout_y="54dp"
android:background="#FFFFFFFF"
android:textSize="12dp" />

</AbsoluteLayout>



/* 参数一多,有些人就头晕了。这里解说下,各个参数的意思。
* 第一个参数 this 代表的是当前上下文,可以理解为你当前所处的activity
* 第二个参数 getData() 一个包含了数据的List,注意这个List里存放的必须是map对象。simpleAdapter中的限制是这样的List<? extends Map<String, ?>> data
* 第三个参数 R.layout.user 展示信息的组件
* 第四个参数 一个string数组,数组内存放的是你存放数据的map里面的key。
* 第五个参数:一个int数组,数组内存放的是你展示信息组件中,每个数据的具体展示位置,与第四个参数一一对应
* */
java
-------------
SimpleAdapter adapter = new SimpleAdapter(this,getData(),R.layout.listviewdemo2_sub,  
new String[]{"title","info","img"},
new int[]{R.id.title,R.id.info,R.id.img});
listView2.setAdapter(adapter);


private List<Map<String, Object>> getData() {  
List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

Map<String, Object> map = new HashMap<String, Object>();
map.put("title", "G1");
map.put("info", "google 1");
map.put("img", R.drawable.android0001);
list.add(map);

map = new HashMap<String, Object>();
map.put("title", "G2");
map.put("info", "google 2");
map.put("img", R.drawable.android0002);
list.add(map);

map = new HashMap<String, Object>();
map.put("title", "G3");
map.put("info", "google 3");
map.put("img", R.drawable.android0003);
list.add(map);

return list;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值