0

i have to draw a listview with sections. To be precise i have to display events in the different months of the year. In this the month name becomes the header of the section and the event in that month become the data inside the section.

i am currently getting data in a hashmap, with the month name as the key and an array on events in that month as an object.

how do i achieve this effect? In iphone app development i believe there is a inbuilt functionality for this, is there such a provision in android?

thank you in advance.

NOTE: why can't i use a TableView inside a ScrollView to do the above? There is no need to go through adapters and all when i can do this. The process should become very less complex.

user590849
  • 11,655
  • 27
  • 84
  • 125
  • the section header listing is such a common feature.. .why can't android guys come up with a solution? i mean are they saying that just because we can find work arounds, we don't need to optimize the process? – user590849 May 08 '11 at 12:39
  • Perfectly working code for this problem [here](http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09/) – Nitin Aug 24 '11 at 10:55
  • I haven't seen a perfect answer for this, but here's the same question with a few suggestions: http://stackoverflow.com/questions/2394514/how-to-generate-a-listview-with-headers-above-some-sections – Shawn Lauzon May 08 '11 at 06:50
  • If you're using Cursors, you can use my [SectionCursorAdapter](https://github.com/monxalo/android-section-adapter). – monxalo Sep 01 '11 at 10:27
  • [Here's a really simple implementation](https://github.com/spencerkohan/SectionListAdapter) with an iOS UITableViewDelegate style interface – sak Nov 02 '11 at 14:07

1 Answers1

0

Due to the lack of built-in support for sectional header lists, we have to deal with section-header and caption views separably, where sectional-header should be non-clickable and should not be counted as a ListView child. For this you have to override some methods like getView, getCount etc of an efficient adapter.

Search separatedListAdapter for more references.

casperOne
  • 73,706
  • 19
  • 184
  • 253
Shailendra Singh Rajawat
  • 8,172
  • 3
  • 35
  • 40
  • in the example you have given over here, the author is using the same view type for the header and the section contents. i have a different view for each. so rather than using a array adapter for sections i have made my own adapter. i have used the same arrayadapter for headers as given in the code. but when i execute the code it is giving an error of `ResourceNotFoundException`. it is not able to find the resource in the array adapter which we have used for headers.... – user590849 May 09 '11 at 07:15