setEmptyView上的ListView不显示在一个Android应用程序视图

问题描述:

您好有从一个ListView所述setEmptyView方法的一个问题。

Hi have a problem with the setEmptyView method from a ListView.

下面是我的Java code:

Here is my Java code:

ListView view = (ListView)findViewById(R.id.listView1);
view.setEmptyView(findViewById(R.layout.empty_list_item));

ArrayAdapter<Session> adapter1 = new ArrayAdapter<Session>(this, android.R.layout.simple_list_item_1, 
        android.R.id.text1, MainController.getInstanz().getItems());
view.setAdapter(adapter1);

empty_list_item:

empty_list_item:

<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:text="@string/emptyList" >

</TextView>

列表视图:

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

什么是错我的code? 当我有项目我看到他们在列表中。但是,当列表为空我没有看到的TextView

What is wrong with my code? When I have items I see them in the list. But when the list is empty I don't see the TextView.

问题是,我必须做一个addContentView:

the problem is, i have to do a addContentView:

View empty = getLayoutInflater().inflate(R.layout.empty_list_item, null, false);
addContentView(empty, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
view.setEmptyView(empty);

现在其优良