Add a header/footer in a listview in xml

Scorpio picture Scorpio · Apr 15, 2014 · Viewed 15.2k times · Source

I know how to add a header or a footer in JAVA, but I was wondering if I could add it straight in the XML. I wouldn't want to simulate this, but really add it as footer or header!

Answer

olegr picture olegr · Apr 15, 2014

No, I don't think that it is possible. Based on ListView source code there are only overScrollHeader/overScrollFooter are available from XML attributes. But these attributes accept only drawables.

If you don't want to use tricks with layouts above/below ListView. You can extend ListView and implement your own footer and header support in customized View. It is not so hard because of footer and header are already implemented. You only have to add XML attributes parsing in your customized View's constructor.