Android: Summary of ListView header/footer findings

Note: This page gets a surprising percentage of traffic. If the subject interests you, you may find better answers at my later entry where I develop an app to try various layouts with ListView.

The issues

  • Scrolling with the list
  • Visibility
  • Ability to navigate without touchscreen (Dpad, trackball)
  • Ability to include interactive elements (text entry, buttons)
  • Doing with code vs. inside resources

Strategies

Strategies for headers and footers on ListView and pros/cons:

Static header: Element in your layout that precedes the ListView. Doesn’t scroll with list, so it takes up space. But is always visible and you can navigate to it and use interactive elements. Also can be done inside resources.

List header: Element added to the ListView with addHeaderView. Scrolls with the list, but is invisible if an empty view is being shown. Can be navigated to but interactive elements on it can’t be. Can’t be done within resources, currently must be attached within code.

Empty view: Standard ListView layout feature.  Only visible when the list is empty, and can’t be a reuse of another view in the activity (so any interactive elements have to be wired up separately from e.g. a header). Interactive elements can’t be navigated.

List footer: Element added to the ListView with addFooterView. Scrolls with the list and is visible even with an empty view. Can be navigated to but interactive elements on it can’t be, and the virtual keyboard is likely to cover the view if the list has even a few items. Can’t be done within resources, currently must be attached within code.

Static footer: Element in your layout that comes after the ListView. This is a non-starter because once your list is as long as the screen, this element can’t be scrolled to at all.

My conclusion

If you’re trying to have a nice interactive element in your list for adding list items, probably the best bet is to make it a non-interactive list header or footer that opens a dialog on click or a context menu on long-click. If you really want to avoid popping things up and want to have interactive elements, then go ahead and put them in a list header, as most everyone will be using the touch screen anyway, just be aware of the navigational issues.