I would like to have the listview in a ListActivity be displayed with the header and footer visible all the time even if the list data is empty.
An empty list causes
This answer is a bit late, but you can simply override BaseAdapter.isEmpty() to return false.
public boolean isEmpty() {
return false;
}
I found that header/footer will always be visible if you don't call ListView.setEmptyView.
Instead, manually show/hide your empty view:
emptyView.setVisibility(list.size() == 0 ? View.VISIBLE : View.GONE);
You could use my MergeAdapter for this. Add the header view, add the data adapter, and add the footer view. They will all scroll in unison, and the header and footer will persist even if the adapter in the middle has no rows.
I meet the same issue, if ListView has no item, you could ListView.setAdapter(new SomeAdapter(new ArrayList())); and the header is also visible.
Ok, this workaround is a hack. But, without having to create a fake item.
For an ArrayAdapter you can add a null item... i.e.
myAdapter.add(null);
And, in the MyAdapter getView(..) you do something like:
myItem = getItem(position);
if (myItem == null) {
return getLayoutInflater().inflate(R.layout.my_empty_row, null);
} else {
...
}
Make your empty view include your header.
i.e.
<ListView />
<RelativeLayout
android:id="@android:id/empty"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
// Add whatever you want here including your header
</RelativeLayout>