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
In my case I had both header and footer views.
I placed my mEmptyView
in footer view.
First, as user1034295 mentioned, I overrided adapter's isEmpty()
method:
@Override
public boolean isEmpty() {
// If not overridden, then this will return `true` if your list is empty
// Thus, you won't see header/footer views
return false;
}
ExpandableListView adapter's getGroupCount()
. Override appropriate method for your adapter.
@Override
public int getGroupCount() {
int size = null != mData ? mData.size() : 0;
if (0 == size) mHostFragment.toggleEmptyView(true);
else mHostFragment.toggleEmptyView(false);
return size;
}
In you activity/fragment
public void toggleEmptyView(boolean show) {
if(show && mEmptyView.getVisibility() != View.VISIBLE)
mEmptyView.setVisibility(View.VISIBLE);
else if (!show && mEmptyView.getVisibility() != View.GONE)
mEmptyView.setVisibility(View.GONE);
}
mEmptyView
is a child in ListView
's footer view.
So, when your list becomes 0 sized you'll get your header/footer views remained + mEmptyView
will become visible.