Skip to content Skip to sidebar Skip to footer

Setemptyview() Doesn't Seem To Work For (sherlock)listfragment

I have a ListFragment and I want to set its empty view, so I use the following code: View emptyView = getLayoutInflater().inflate(R.layout.collection_empty_view, null); detailFragm

Solution 1:

The empty view has to be in the same view hierarchy as the list view. Inflating it that way won't work.

Generally I create a layout in the format below:

<Layout><ListView/><Viewandroid:id="@+id/empty"/></Layout>

Where empty view is the View I want to use as my "empty view". Then in on create I get a reference to the empty view and call setEmptyView() with that reference.

Here's an example from the Android documentation (check out the documentation, it should be applicable to SherlockListFragment):

<?xml version="1.0" encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"android:paddingLeft="8dp"android:paddingRight="8dp"><ListViewandroid:id="@id/android:list"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#00FF00"android:layout_weight="1"android:drawSelectorOnTop="false"/><TextViewandroid:id="@id/android:empty"android:layout_width="match_parent"android:layout_height="match_parent"android:background="#FF0000"android:text="No data"/></LinearLayout>

Solution 2:

You can try something which I'm doing in a fragment of my application. I don't know if it's a good practice but it works!

ViewemptyView= getActivity().getLayoutInflater().inflate(R.layout.empty, null);
getActivity().setContentView(emptyView);

Post a Comment for "Setemptyview() Doesn't Seem To Work For (sherlock)listfragment"