Android:我的ListView单元格的描述部分不会显示

时间:2012-07-11 10:56:40

标签: android listview

我的单元格有以下XML代码(search_cell.xml):

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:orientation="vertical"
    android:paddingLeft="15dp"
    android:paddingTop="3dp"
    android:background="@color/white"
    >

   <TextView android:id="@+id/libelle"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:textSize="16dp"
             android:textStyle="bold"
             />

    <TextView android:id="@+id/valeur"
             android:layout_width="fill_parent"
             android:layout_height="fill_parent"
             android:textSize="10dp"
             android:textStyle="normal"
             />

</LinearLayout>

在我的活动xml文件中:

<ListView
    android:id="@+id/listRecherche"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="150dp" >
</ListView>

在Java中:

list =(ListView)findViewById(R.id.listRecherche);

    ArrayList<HashMap<String, String>> listItem = new ArrayList<HashMap<String, String>>();
    HashMap<String, String> map = new HashMap<String, String>();

    map.put("libelle", "Microsoft");
    map.put("valeur", "1975");
    listItem.add(map);

    map = new HashMap<String, String>();
    map.put("libelle", "Apple");
    map.put("valeur", "1976");
    listItem.add(map);

    map = new HashMap<String, String>();
    map.put("libelle", "Dell");
    map.put("valeur", "1984");
    listItem.add(map);

    SimpleAdapter mSchedule = new SimpleAdapter (this.getBaseContext(), listItem, R.layout.recherche_cell,
            new String[] {"libelle", "valeur"}, new int[] {R.id.libelle, R.id.valeur});

    list.setAdapter(mSchedule);

这就是我得到的。为什么我看不到年份字段?

enter image description here

非常感谢你的帮助。

2 个答案:

答案 0 :(得分:1)

尝试这个新的search_cell.xml

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="50dp"
    android:orientation="vertical"
    android:paddingLeft="15dp"
    android:paddingTop="3dp"
    android:background="@color/white"
    >

   <TextView android:id="@+id/libelle"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:textSize="16dp"
             android:textStyle="bold"
             />

    <TextView android:id="@+id/valeur"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:textSize="10dp"
             android:textStyle="normal"
             />

</LinearLayout>

您使用fill_parent作为第一个textview height参数。所以这填补了整个父母。所以,我把八个参数改为'wrap_content'

答案 1 :(得分:1)

android:layout_height =“fill_parent”将占据整个高度。相反尝试android:layout_height =“Wrap_content”,它将占用您拥有的内容。