Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List activity with header, footer and empty all visible

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 the empty view to appear and the header and footer to disappear. However my header has filtering UI and should therefore always be visible.

The only way I can make it happen at the moment is if I take the header and footer out of the listview and implement them as static views outside in the activity layout. However then these are always visible and only the data scrolls.

I would prefer for both to just be on top and bottom of the scrolling list. Wrapping it all in a scroll view does not work since then there are two nested scroll views( the list view outside and the wrapping one).

Is there a way to do this nicely apart from a hack like adding a fake record?

like image 894
Manfred Moser Avatar asked Sep 16 '11 19:09

Manfred Moser


2 Answers

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>
like image 156
Blundell Avatar answered Oct 11 '22 12:10

Blundell


This answer is a bit late, but you can simply override BaseAdapter.isEmpty() to return false.

public boolean isEmpty() {
    return false;
}
like image 31
Jim Avatar answered Oct 11 '22 12:10

Jim