リストビューに対して複数の空のビューを作成し、それらをプログラムで設定したいと思います。だから私はListActivityにリストビューを持っています。クライアントがアプリを望んでいるように、アプリにヘッダーバーがあるので、レイアウトは次のようになります。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/providerListLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<include
android:id="@+id/headerBar_ref"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
layout="@layout/header_with_dashboard_button" />
<include
android:id="@+id/loadingView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
layout="@layout/loading_view" />
<RelativeLayout
android:id="@+id/listViewWrapper"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="@id/headerBar_ref" >
<ListView
android:id="@android:id/list"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/headerBar_ref" >
</ListView>
</RelativeLayout>
したがって、2つの空のビューが別々のxmlファイルにあります。リストアクティビティでは、次のように空のビューを設定しようとします。
RelativeLayout rootLayout = (RelativeLayout) findViewById(R.id.listViewWrapper);
RelativeLayout noFavsLayout = (RelativeLayout) this
.getLayoutInflater().inflate(emptyViewLayoutId,
rootLayout);
getListView().setEmptyView(noFavsLayout);
しかし、私がこれを行うと、空のビューが常に存在します。addContentView()を使用してビューを追加しようとしましたが、画面全体を占有します。私はまだS/Oで解決策を見つけることができませんでした