Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Displaying 'No Data' with ListView

Tags:

android

I'm using a ListView, and it is not working properly. Please see my code.

<LinearLayout
    android:id="@+id/playerlist"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
        <ListView 
                android:id="@+id/plist"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content" /> 
        <TextView
                android:id="@id/android:empty"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="NO DATA" />
</LinearLayout>

Well, It works well if the list is empty.

But as the list is short, You can see the 'NO DATA' below the ListView.

If you set the layout_height of the ListView to 'fill_parent', the 'NO DATA' can't appear.

Can anyone help me?

like image 794
Namnamseo Avatar asked Nov 20 '25 18:11

Namnamseo


1 Answers

You must apply setEmptyView(View emptyView) to your listview.

Give your TextView an id, say emptyView;

TextView emptyView = (TextView)findViewById(R.id.emptyView);
yourListView.setEmptyView(emptyView);

should do the trick.

Hope this helps

like image 78
Murat Nafiz Avatar answered Nov 23 '25 06:11

Murat Nafiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!