Android: ListView Fastscroll and its styling

In this Android example, we will see how to create a ListView with fast scroll enabled.

Project Description:

This Android ListView tutorial explains the following,

  • How to create a ListView which displays a list of items (in our example we display a list of fruits).
  • How to enable fast scroll in ListView
  • How to customize fast scroll style attributes such as,
    • Fast scroll thumb drawable
    • Fast scroll text color
    • Fast scroll track drawable
    • Fast scroll preview background


You can use this site to generate drawables and themes which you can copy into your project.

Download “Android ListView FastScroll” – Downloaded 3245 times – 1 MB

Android Project

Create a new Android project and name it as “AndroidFastScrollDemo“.



Create a new file res/values/colors.xml and copy paste the following content.


Open res/values/strings.xml and edit to have the content as shown below.

Layout files


This XML layout file (activity_main.xml) is used to define ListView
Open activity_main.xml file in res/layout and copy the following content.


This XML layout file (list_item.xml) is used for displaying a particular ListView item. It contains a single TextView.
Create a new list_item.xml file in res/layout and copy the following content.


Open res/values/styles.xml and edit to have the content as shown below. Here, fast scroll style attributes are defined.


Create a new file fastscroll_thumb_holo.xml in res/drawable/ and copy the following content. It defines selector for fast scroll thumb for default and pressed states.

Source files

ListAdapter class

Create a new class “ListAdapter” in the package com.androidopentutorials.fastscrolldemo.adapter.

  • This is the custom ListView adapter class which implements SectionIndexer to enable fast scrolling between sections of an AbsListView. A section is a group of list items that have something in common. For example, they may begin with the same letter or they may be songs from the same artist. SectionIndexer provides following methods,
getPositionForSection(int section) returns the starting (first) position of that section with the list adapter
getSectionForPosition(int position) returns the index of the corresponding section within the array of section objects in that given position
getSections() returns an array of objects representing sections of the list.

Understanding getPositionForSection(section) and getSectionForPosition(position)
For example if the index of section B is 1 and the indexed column of the cursor has the following data

  • getPositionForSection(0) – returns 0
  • getPositionForSection(1) – returns 4
  • getPositionForSection(2) – returns 7


This is the main activity class. To enable fast scroll in ListView, do the following steps,

  • Set fast scroll mode to your ListView
    • listViewInstance.setFastScrollEnabled(true);
  • Make your adapter implement android.widget.SectionIndexer interface and override the methods to see an alphabet letter on which you are currently on during fast scrolling.

  • The string array is retrieved from strings.xml. We create an instance of ListAdapter which implements SectionIndexer and set this to the ListView.


Running the app will display the following output.

  • Pingback: How to add a fast-scroller to the RecyclerView? | DL-UAT

  • Djul Lau

    Hey, thanks for this great tutorial !

    I’ve just used it to add fastscroll to my app and I’d like to add a few things.

    1. The adapter contains a bug to me :
    // HashMap will prevent duplicates
    mapIndex.put(ch, x);

    This will put the leave the last found index with the letter in the hashmap and I think it should be the first (was messing the fast access in my very long list).

    Something like (assuming the list is ordered) :

    if (!mapIndex.containsKey(ch))
    mapIndex.put(ch, x);

    2. You don’t explain why getSectionForPosition() is not implemented (always returns 0).
    It seems to be called by the listview even if implementing it made no visible difference in my case.

    3. I think the initial list must already be ordered (or weird things happen) and so there is no need to sort the sections (the linkedlist retains the insert order).



    • Abhishek Balani

      +1 for

      if (!mapIndex.containsKey(ch))mapIndex.put(ch, x);

  • Half Moon
  • Pingback: Fastscroll with chars get onClick event on char View - HTML CODE

  • Carnegi

    It Gives error on “fastscroll_thumb_default_holo”

    Error:(6, 29) No resource found that matches the given name (at ‘drawable’ with value ‘@drawable/fastscroll_thumb_default_holo’).