第一种 继承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;
}

更多相关文章

  1. 安卓隐藏标题栏状态栏 ,实现全屏效果
  2. android EditText设置弹出数字输入法键盘
  3. Android(安卓)Activity 常用功能设置(全屏、横竖屏等)
  4. Android(安卓)SDK各版本源码
  5. android定位个人当前位置
  6. ListActivity setContentView 错误
  7. Android安卓51个开源代码
  8. Android安卓51个开源代码
  9. 使用命令建立简单的布局

随机推荐

  1. 23 个非常实用的 Shell 拿来就用脚本实例
  2. dblink不稳定造成 cursor: pin s wait on
  3. 新人和老人关于数据思维的50个区别
  4. ORA-15040 ora-15017ASM磁盘无法挂载故障
  5. 面试官常考的 21 条 Linux 命令
  6. Go:变量声明,字符类型
  7. lob字段的direct path read等待导致的性
  8. php多维数组创建及遍历
  9. 从运维角度测试全局死锁以及带来的问题
  10. 你向 MySQL 数据库插入 100w 条数据用了