Android 为可扩展列表设置空视图无效

Android 为可扩展列表设置空视图无效,android,layout,expandablelistview,Android,Layout,Expandablelistview,因此,我给我的可扩展列表提供了一个过滤选项,当过滤器没有任何结果时,我想显示一条空消息,上面说“没有”会导致可扩展列表预定义区域的高度和宽度,但我有一段非常艰难的时间 当我将空视图添加到可展开列表所在的布局时,如下所示: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_wi

因此,我给我的可扩展列表提供了一个过滤选项,当过滤器没有任何结果时,我想显示一条空消息,上面说“没有”会导致可扩展列表预定义区域的高度和宽度,但我有一段非常艰难的时间

当我将空视图添加到可展开列表所在的布局时,如下所示:

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="10"
android:id="@+id/orderMenu">

<EditText
    android:layout_width="fill_parent"
    android:layout_height="0dp"
    android:id="@+id/searchBarMenu"
    android:layout_gravity="center_horizontal"
    android:layout_weight="1"
    android:visibility="gone"
    android:inputType="text"
    android:hint="Search for keyword(s), divided by comma"
    android:singleLine="true"
    android:textSize="15dp" />

<TextView
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:textAppearance="?android:attr/textAppearanceLarge"
    android:text="Large Text"
    android:id="@+id/ResturantName"
    android:layout_gravity="center_horizontal"
    android:paddingTop="10dp"
    android:textSize="30dp"
    android:layout_weight="1" />


<view
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    class="com.paze.CustomViews.MenuExpandableList"
    android:id="@+id/expandableListView"
    android:layout_gravity="center_horizontal"
    android:layout_weight="8" />

<Button
    android:layout_width="175dp"
    android:layout_height="0dp"
    android:text="Finish Order"
    android:id="@+id/proceedButton"
    android:layout_gravity="center_horizontal"
    android:singleLine="true"
    android:layout_weight="1" />

     <TextView
    android:id="@android:id/empty"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:textSize="20dp"
    android:text="No Items In your order"
    android:layout_centerInParent="true"
    android:layout_gravity="center_horizontal"/>

    </LinearLayout>
where empty是一个特殊布局上的视图,而不是我为此创建的可扩展列表

<如何在空可扩展列表中间设置视图?< /p> 注: 筛选时,我设置了一个新适配器,而不更新当前适配器的列表

非常感谢

您必须将特殊布局添加到包含ListView层次结构的活动中。然后将整个布局设置为列表的空视图。使用布局可以将文本放置在任何需要的位置

@Override
public void onCreate(Bundle savedInstanceState) {
...
final View inflated = LayoutInflater.from(this).inflate(R.layout.empty_layout, null);
addContentView(inflated, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
listView.setEmptyView(inflated);
...
}
基于:

@Override
public void onCreate(Bundle savedInstanceState) {
...
final View inflated = LayoutInflater.from(this).inflate(R.layout.empty_layout, null);
addContentView(inflated, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
listView.setEmptyView(inflated);
...
}