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 5468 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.