android listviews: header and footer views

jlim picture jlim · Jan 7, 2010 · Viewed 24k times · Source

In my ListActivity, I need header and footer views (on the top and bottom of the list) to be used as previous page and next page buttons on my list, respectively, because I want to display only 20 items at a time.

I set my header and foot views by doing:

getListView().addHeaderView(myHeaderView);
getListView().addFooterView(myFooterView);
setListAdapter(adapter);

This works fine, but I need to dynamically remove and add these header and footer views, because some pages of my list may not have a next page button or a previous page button.

The problem is, I cannot call addHeaderView or addFooterView after I have called setListAdapter.

Is there a way around this?

Answer

Roman Nurik picture Roman Nurik · Jan 7, 2010

Why not just collapse the header and footer to zero height, or gray out the buttons (even better).

And the best user experience, in my opinion, would be to dynamically load more items when needed (i.e. upon scroll), like the built-in Gmail app does.