Android: ListView with Alphabetical side index

In this Android Example, we will see how to create a ListView with alphabetical side index.

Project Description:

This Android ListView tutorial explains the following,

  • How to create a ListView displaying list of fruits.
  • How to display alphabetical index at right side of the ListView
  • Display corresponding list items by selecting a letter from the alphabet indexer at the right.

Download “Android ListView With Side Index” – Downloaded 5079 times – 1 MB

Android Project

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


Layout files


This XML layout file (activity_main.xml) is used for defining ListView and a LinearLayout to display side index.

Open activity_main.xml file in res/layout and copy the following content.


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


Open res/values/strings.xml and edit to have the content as shown below. A string array is defined to have list of fruits.

Source files


This is the main activity class.

  • Here, a java.util.Map is created with key as alphabets and value as its index position.
  • We generate the map by calling getIndexList() method.

  • displayIndex() displays alphabetic indexer at the right and sets OnClickListener for TextView.
  • When a letter from alphabet indexer is selected, it displays corresponding list item.

Complete Code:


Running the app will display the following output.

  • Alex Mansour

    Hello , how to populate the listview from online JSON file with keeping the same functionality of Alphabetical order . Thanks

    • Bruno Cardoso

      Hi Alex Mansour, did you discover how to do this from a json file?

  • raman kumar

    this works great but the order in not alphabetical so i need you to provide the correct code to display alphabetically

  • Carl Smith

    Excellent tutorial. Very easy to follow. Many thanks!

  • fikriyogi

    Excellent tutorial, but how to start another activity from this listview using intent?

  • Eko Wiyatnanto

    Excellent, but i’m using fragment and i got error in textView.setOnClickListener(this); . can you fix it? please help me

    • Who wants me? I’m here

      &#9658 &#9668

    • Nijas

      implement View.OnClickListener.

    • Vinod Raaj

      textView.setOnClickListener(getActivity()); i hope i m not too late :-)

  • Half Moon
  • Rahul Otwar

    sir i am beginner and i am accessing sd card item so coulde you please tell me how to add alphabetic side index for sd card list

  • Pingback: android ListViewの調査メモiOSだとすぐできるけどけど - LOCAL COLOR BLOG

  • Frans Appel

    Nice, but how can I use custom adapter with the index ? (more lines in a listviewrow)

  • Hari Krishna

    ya …good ur create on static then how to create on dynamic…..give me hint

  • manoj

    If the list not having any letter starting with that then the letter is also gone in the scroll. how to fix this

  • pietjestraat

    I would like to create a separate class for the side index. How can I replace “this” within textView.onClicklistener(this) in the parameter list of your routine displayIndex. I believe this needs to be passed from calling Fragment.