I am using addHeaderView
to add a view item to the top of a ListView
. I also have a TextView
to display a message saying there are no items in the list.
Here is the layout:
<ListView android:id="@android:id/list" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <TextView android:id="@android:id/empty" android:layout_width="fill_parent" android:layout_height="fill_parent" android:text="@string/list_empty" android:gravity="center" android:textAppearance="?android:attr/textAppearanceMedium" />
And the Java code:
final ListView listView = getListView(); final View view = getLayoutInflater().inflate(R.layout.list_item_add, listView, false); listView.addHeaderView(view, null, true);
When there are items in the ListView then the header is shown but if I delete all items in the list (except the header view) then the header view disappears.
I would like the header view to be visible in the list view whether there are items in the list or not.
Thanks,
Remove the @android:id/empty
view from your layout, or override/subclass your adapter to return false from isEmpty()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With