Navigation Drawer : add headers in listview

别来无恙 提交于 2019-11-28 17:19:09

You would do that the same way as you would add headings in any other ListView, by teaching your ListAdapter to return heading rows as well as detail rows. At the low level, this involves overriding methods like getViewTypeCount() and getItemViewType() in your ListAdapter, plus having getView() know the difference between the row types. Or, use an existing high-level implementation like https://github.com/emilsjolander/StickyListHeaders or http://code.google.com/p/android-amazing-listview/ or any of the others found when searching for android listview headers.

The other answers are correct.

I have found a really good example of customising the view to contain two types of items : menu section and menu item. Of course you can change it to be whatever you want.

The example also contain an implementation of an abstract activity class that every activity with a nav drawer inherits from.

http://www.michenux.net/android-navigation-drawer-748.html

You will have to subclass BaseAdapter and use this instead of SimpleAdapter in the ListView.

You supply the adapter with stuffed data, where the extra data is the titles. The titles and the listitems themselves will be members of the same common class. Then in the adapter you decide based on the data item if the actual view is a title or an item and inflate it accordingly.

UPDATE:

Here is a good example of this: http://w2davids.wordpress.com/android-sectioned-headers-in-listviews/

This actually separates titles from data items and uses convertView correctly, unlike the solution I used so far in my previous apps.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!