Another fast scroller helper for ListView
Android’s ListView has a built-in way to implement fast (indexed) scrolling.
As useful as it is, it has two limitations that sometimes can be critical:
– A section name is assumed to be a single letter.
– If the list content changes over time, it’s difficult to update the section list on the go.
The fast scroller helper class in the framework is closely integrated with AbsListView, and so it does not seem possible to just replace it with another implementation, or change the way it behaves.
I needed one of these for my current project, and found a fast scroller that was posted on Google Code by Android’s Dianne Hackborn.
This code is from 2008, before there was a fast scroller implementation in the framework, and so its way of interacting with the list is different. This class is derived from FrameLayout and should be used in the layout XML file as the list view’s parent.
I combined this code with the fast scroller from the Ice Cream Sandwich sources. The result looks like this:
This class is used the same way as the FastScrollView linked to above – it should be inserted into the layout XML as the list view’s parent.
It has a method for updating the section index, which can also optionally reset the current drag tracking state (or not, specified as a parameter).
The section overlay’s size and its font size are specified as dimension resources. Long (over 1 character) section names are displayed correctly.
Finally, I also fixed some rendering issues on Android 3.0 when running with hardware acceleration enabled.
The code is too large to post here, so I uploaded it to Google Code. A sample / test project is included.