您的位置:首页 > 移动开发 > Android开发

SimpleAdapter添加了元素后没有内容显示

2013-09-11 18:46 218 查看
布局文件
<?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中,所以上面的布局文件应该写两个
 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐