第一种 继承ListActivity
//xmlUI的代码
<?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:background="#FFFFFF"
>
<ImageView android:layout_width="wrap_content" android:src="@drawable/icon" android:layout_height="wrap_content" android:id="@+id/img"></ImageView>
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
></TextView>
</LinearLayout>
//Activity类里面的代码
SimpleAdapter simpleAdapter = new SimpleAdapter(this, getData(),
R.layout.menu, new String[] { "title", "img" }, new int[] {
R.id.title, R.id.img });
setListAdapter(simpleAdapter);
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", " 票 劵 列 表");
map.put("img", R.drawable.icon);
list.add(map);
map = new HashMap<String, Object>();
map.put("title", " 历 史 记 录");
map.put("img", R.drawable.icon);
list.add(map);
map = new HashMap<String, Object>();
map.put("title", " 授 权 码");
map.put("img", R.drawable.icon);
list.add(map);
return list;
}
第二种 继承Activity
//xmlUI的代码
<?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:background="#FFFFFF"
>
<ImageView android:layout_width="wrap_content" android:src="@drawable/icon" android:layout_height="wrap_content" android:id="@+id/img"></ImageView>
<TextView android:id="@+id/title" android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content"
android:layout_gravity="center_vertical"
></TextView>
</LinearLayout>
//Activity类里面的代码
SimpleAdapter simpleAdapter = new SimpleAdapter(this, getData(),
R.layout.menu, new String[] { "title", "img" }, new int[] {
R.id.title, R.id.img });
ListView listView = new ListView(this);
listView.setAdapter(simpleAdapter);
setContentView(listView);
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", " 票 劵 列 表");
map.put("img", R.drawable.icon);
list.add(map);
map = new HashMap<String, Object>();
map.put("title", " 历 史 记 录");
map.put("img", R.drawable.icon);
list.add(map);
map = new HashMap<String, Object>();
map.put("title", " 授 权 码");
map.put("img", R.drawable.icon);
list.add(map);
return list;
}