动态刷新ListView数据:[url]http://panyongzheng.iteye.com/admin/blogs/1453777[/url]
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;
}