Search code examples
androidandroid-listviewandroid-custom-view

Android PinnedHeaderListView with multiple headers


I'm looking for a library/view that will allow me to have a "Pinned Header" list view where multiple headers stack on the top. So similar to the way the current Contacts apps work but instead of the A going away when the B reaches the top, the B would stack below it, followed by C and so on.

I understand that screen real-estate could become an issue if there are too many headers but my use case won't require more than 2 or 3 headers so it shouldn't be an issue in the immediate future.

I've been working with some of the current PinnedHeaderListViews (like https://github.com/JimiSmith/PinnedHeaderListView) but I don't see an easy way to adjust these to work how I need it. Does anyone know of any libraries that would accomplish this or where I should start tweaking another library?

Thanks in advance


Solution

  • EDIT:

    The solution I talk about below had one major flaw, it didn't allow for the pinned headers to respond to touch events. This was a major concern for me as I needed each header to be a button that had its own unique response. I worked on this issue and after a lot of tweaking and changes I got a system that is closer to what I was looking for. It no longer pins view on the bottom but will allow for the headers to accept touch events whether pinned or in the list. If you want to try it out, the discussion and sample project are located here:

    https://groups.google.com/d/msg/android-developers/VMr3CA_H798/G23oRmpfLKgJ

    ORIGINAL:

    After more searching and a little tweaking I found a solution that will work for me. I ended up using some stuff that was buried in the Android source code and tweaked it a little to work with the data structures I need...

    In the CompositeCursorAdapter I just removed the Partition class and replaced it with the data structure I needed. Those updates caused some updated in PinnedHeaderListAdapter. I also had to create another adapter extending PinnedHeaderListAdapter that handled all of the final method implementations of PinnedHeaderListAdapter and CompositeCursorAdapter. Using this I ended up with a list that looked like this...

    One pinned header Stacked pinned headers

    If anyone needs more details, comment below and I'll try to answer any questions or post code as needed