第一种 继承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. Android安卓51个开源代码
  2. Android 代码改变图片颜色android:tint="@color/main_color" and
  3. Kotlin 写 Android 单元测试(四),Robolectric 在 JVM 上测试安卓相
  4. 修改 framework 代码的经验和踩过的坑
  5. android常用颜色代码定义

随机推荐

  1. Android(安卓)特殊符号的转码
  2. Android(安卓)监听事件
  3. 客户关系管理
  4. Android面试题总结加强版(二)
  5. android 学习 之 布局(上)
  6. 用android view中的tag传送数据
  7. Android(安卓)EditText 实现监听实例
  8. android――资源目录
  9. 自己总结的目前Android通用的流行框架大
  10. kinect手势识别后,利用识别效果控制鼠标