ListView
s cant' be entirely define in XML. There are 2 key parts to it, however, that can be defined in XML, plus the footer and header if you so choose. All 4 of these can be defined in XML, but the relationship between them must be defined in code. In theory these could be combined, and in fact are done so in ListPreferences, but the standard Android context doesn't allow for that.
So, the 4 parts that can be defined in XML are:
ListView
- Contains location, size, dividers, and background- Adapter View- Shows what a single row looks like
- Header- This is a custom first row in your list
- Footer- This is a custom last row of your list
All of these, for better or worse, are connected at runtime. The adapter controls the flow between them. The code you have is the best wa that can be done, unfortunately the XML simply isn't sufficient to completely define the ListView in XML.