ListView里面的Fragment android

时间:2012-08-23 13:31:45

标签: android android-listview android-fragments

我在片段中实现列表视图时遇到了麻烦。

xml代码是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >


        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:src="@drawable/jo_logo" />

    </LinearLayout>

    <ListView
        android:id="@+id/listView1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1" >
    </ListView>

</LinearLayout>

简单的ImageView以及之后的列表视图。 我已经尝试过实施:

ArrayAdapter<String> adapter = new ArrayAdapter<String>(getActivity().getBaseContext(), 
            android.R.layout.simple_list_item_1, viewList);
    setListAdapter(adapter);

其中viewList是View [],在onCreateView函数上。 似乎它在片段中不起作用。 我需要的是第一个视图是ImageView,第二个是ListView,而且都在片段内。

请帮助,提前谢谢,udi

1 个答案:

答案 0 :(得分:2)

在您的布局xml中将android:id="@+id/listView1"更改为android:id="@android:id/list",否则ListActivity / ListFragment将找不到您的ListView