利用ListView完成列表的一个信息展示

先晒上最后的一个结果吧。
这里主要是用了Adapter和ArrayList 以及HashMap
步骤大部分跟书上的差不多。
没有直接用ListView
而是用普通的布局配合Text来实现的
部分代码如下:
//private ListView listView;
// @Override
// public void onCreate(Bundle savedInstanceState) {
// super.onCreate(savedInstanceState);
//
// SimpleAdapter adapter = new SimpleAdapter(this, getData(), R.layout.activity_main, new String[]{
// "name", "age", "email", "place"}, new int[]{R.id.name, R.id.age, R.id.email, R.id.place});
// setListAdapter(adapter);

//}

// private ArrayList<Map<String, Object>> getData() {
// ArrayList<Map<String, Object>> list = new ArrayList<Map<String, Object>>();
// Map<String, Object> map = new HashMap<String, Object>();
// map.put("name", "姓名:蔡志坤");
// map.put("age", "年龄:25");
// map.put("email", "邮箱:ffczk86@gmail.com");
// map.put("place", "厦门市");
// list.add(map);
// map.put("name", "姓名:李杰华");
// map.put("age", "年龄:25");
// map.put("email", "邮箱:aa@bb.com");
// map.put("place", "漳州市");
// list.add(map);
// map.put("name", "姓名:张亮");
// map.put("age", "年龄:25");
// map.put("email", "邮箱:cc@gmail.com");
// map.put("place", "厦门市");
//list.add(map);
// map.put("name", "姓名:陈旭");
// map.put("age", "年龄:25");
// map.put("email", "邮箱:ccadd@gmail.com");
// map.put("place", "厦门市");
// list.add(map);
// map.put("name", "姓名:刘玄德");
// map.put("age", "年龄:25");
// map.put("email", "邮箱:ffczk86@gmail.com");
// map.put("place", "福州市");
// list.add(map);
// return list;
// }

//}
然后是 xml里的代码:
//
//<LinearLayout
// xmlns:android="http://schemas.android.com/apk/res/android"
// xmlns:tools="http://schemas.android.com/tools"
// android:id="@+id/activity_main"
// android:layout_width="fill_parent"
// android:layout_height="fill_parent"
// android:orientation="horizontal"
// tools:context="cn.edu.niit.homework3.MainActivity">
//<LinearLayout
// android:orientation="vertical"
// android:layout_width="match_parent"
// android:layout_height="wrap_content">
// <TextView
// android:id="@+id/name"
// android:layout_width="match_parent"
// android:layout_height="0dp"
// android:textSize="16sp"
// android:layout_weight="1"/>
// <TextView
// android:id="@+id/age"
// android:layout_width="match_parent"
// android:layout_height="0dp"
// android:textSize="16sp"
// android:layout_weight="1"/>
// <TextView
// android:id="@+id/email"
// android:layout_width="match_parent"
// android:layout_height="0dp"
// android:textSize="16sp"
// android:layout_weight="1"/>
// <TextView
// android:id="@+id/place"
// android:layout_width="match_parent"
// android:layout_height="0dp"
// android:textSize="16sp"
// android:layout_weight="1"/>
//

//

posted @ 2017-05-01 19:49  王子轩1  阅读(304)  评论(0编辑  收藏  举报