I'm looking to emulate the functionality in the latest Music app, namely the nice little cursor that pops up which allows one to scroll super fast to the artist/album/track they're looking for:
Is there a method to enable functionality like this in a ListView
in the Android SDK?
Here is the subclass of ArrayAdapter I'm using. Note that the
objects
I pass in has already been sorted alphabetically, withCollections.sort(objects)
.setFastScrollEnabled(true);
(http://developer.android.com/reference/android/widget/AbsListView.html)
I found a great solution here... Works great with a huge list... Nice and fast... no loading time.
Have your list adapter implement SectionIndexer. The music app also makes use of AlphabetIndexer to do some of the heavy lifting. Also use
setFastScrollEnabled(true)
on the actualListView
to enable this.Edit: If you're not using a CursorAdapter, you won't be able to use AlphabetIndexer. You might try looking at the implementation here and seeing how hard it would be to adapt it to work with an ArrayAdapter.
To collect the details about the items shown in a listview, you can do this:
Isn't this a bit simpler? Here, 'songs' is an arraylist of Song objects. You can even get the last visible item by adding firstVisibleItem + visibleItemCount. I found this technique to be very useful. So then you would get the first letter of each song. I assume the gray box containing the letter in the music app you posted is a dialog box of sorts?
Anyway, hope this helps. I realise I'm late, but this is for future people
On anddev.org I found this tutorial: Alphabetic FastScroll ListView - similar to Contacts
It also contains a short demo-video
Hope it helps!