布局文件
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<!-- 定义一个List -->
<ListView
android:id="@+id/mylist"
android:layout_width="fill_parent"
android:layout_height="fill_parent" />
<!-- 定义ImageView作为List的一部分 -->
<ImageView
android:id="@+id/header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="2dp" />
<!-- 定义TextView作为List的一部分 -->
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16dp"
android:gravity="center_vertical"
android:paddingLeft="10dp" />
</LinearLayout>
设置主布局
super.onCreate(savedInstanceState);
setContentView(R.layout.simpleadapter_listview_main);
在创建SimpleAdapter 时,item要有自己的layout
SimpleAdapter simpleAdapter = new SimpleAdapter(this,
listItems,
R.layout.listview_main,
new String[] {"header", "personName"},
new int[] {R.id.header, R.id.name});
imageview和textview不是写在主layout里,而是写在自己的item layout中,所以上面的布局文件应该写两个