Android ArrayAdapter正在为ListView中的每个项目重复UI头

Android ArrayAdapter正在为ListView中的每个项目重复UI头,android,listview,user-interface,android-arrayadapter,Android,Listview,User Interface,Android Arrayadapter,在UI中显示项目列表时,我面临一个问题 我的UI布局页面布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/ListOfRecordsContainer" android:layout_width="fill_parent" android:l

在UI中显示项目列表时,我面临一个问题

我的UI布局页面布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ListOfRecordsContainer"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#454545"
    android:orientation="vertical" >

    <include
        android:layout_weight="1"
        layout="@layout/header" />

    <TextView
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ListOfRecords"
        android:layout_width="fill_parent"
        android:layout_height="0dp"
        android:layout_weight="0.01"
        android:padding="1dp"
        android:textSize="12sp" >
    </TextView>

</LinearLayout>
预期结果是

<Header Button for LogOut>
Item1
Item2
代码如下所示:


如果我遗漏了什么,请提供帮助。

我猜您提供的XML被用作行布局,这意味着:

<include
    android:layout_weight="1"
    layout="@layout/header" />

并从行布局中删除include元素。

使标题成为单独的XML布局,并使用addHeaderView添加到listview。即:

    View header = (View)getActivity().getLayoutInflater().inflate(R.layout.listview_header_row, null);
    lv.addHeaderView(header);

希望这有帮助

非常感谢。这个解决方案是可行的,但假设我需要在列表上方有一个搜索栏来搜索列表中的项目,另外还有一个列表标题……这怎么可能呢?有很多方法可以做到这一点,事实上,这里有一个完整的主题。如果你需要特别的帮助,请毫不犹豫地提出一个新问题,提供和你在这里一样多的细节。当然,非常感谢。非常感谢,非常感谢。这个解决方案是可行的,但是假设我需要在列表上方有一个搜索栏来搜索列表中的项目,另外还有一个列表的标题……这怎么可能呢?
<include
    android:layout_weight="1"
    layout="@layout/header" />
View header = getLayoutInflater().inflate(R.layout.header, null);
listView.addHeaderView(header);
    View header = (View)getActivity().getLayoutInflater().inflate(R.layout.listview_header_row, null);
    lv.addHeaderView(header);