2

I would like to create section headers in list fragment but really i don't know how to achieve that.. Am new to fragment.. I googled this but i couldn't find anything to achieve section headers in list fragments.. I referred here, here and my expected output is enter image description here. Help me in achieving this. Thanks in advance.

Community
  • 1
  • 1
AndroidOptimist
  • 1,419
  • 3
  • 23
  • 38
  • Reffered to: http://stackoverflow.com/questions/7943802/how-to-draw-a-section-header-in-android-listview-just-like-the-ioss-uitableview – umair.ali Oct 28 '13 at 09:21
  • @umair.ali i would like to create section header in list fragment not in listview. – AndroidOptimist Oct 28 '13 at 09:22
  • I think there would be no major difference in implementing header with list view or list fragment...you just need to deal with you adapter to achieve this... – umair.ali Oct 28 '13 at 10:02

2 Answers2

0

You could use an ExpandableListView that comes expanded by default and disabled to expand.

Or, you could still use a ListView and create a custom adapter. Depending of the current element in the list (category, or item) you will inflate appropriate layouts. A search on google by "android listview with categories" revealed this tutorial which addresses your question.

Andy Res
  • 15,963
  • 5
  • 60
  • 96
0

you should override getViewType and getViewTypeCount in your custom adapter. getViewTypeCount should return 2, 1 for the normal view and 1 for the header view, and getViewType, should return 0 for the header section and 1 for the normal entry. You will get two null convertView.

Blackbelt
  • 156,034
  • 29
  • 297
  • 305