I managed to get pinned headers working on the ExpandableList1 APIdemo .
The most difficult problem I have encountered is figuring out how to get SectionIndexer to play well with expandable lists. As shown in my question, I thought that all this is wrong. In my initial attempt to solve this problem, I created a SectionIndexer object in MyExpandableAdapter and matched it with my data, similar to how it is done in the Contacts application and Peterβs example. This works in the Contacts application because the positions of the flat list statically correspond to the data set. When expanded, the list items with flat lists change as groups expand and exit.
So, the solution is not to display the section indexer in the data, but in the instance of your ExpandableListView. With this solution, you donβt even need the SectionIndexer object used in the examples. You just need to wrap SectionIndexer implementation methods around ExpandableListView methods as follows:
@Override public int getPositionForSection(int section) { return mView.getFlatListPosition(ExpandableListView .getPackedPositionForGroup(section)); } @Override public int getSectionForPosition(int position) { return ExpandableListView.getPackedPositionGroup(mView .getExpandableListPosition(position)); }
There are, of course, other changes you need to make for this to work, but these methods are key. I will send the full code to google or github code and the link soon. Extensible lists with attached headers look great!
joecan
source share