Android ExpandableListView

Android ExpandableListView

Expandable list view is used to group list data by categories. It has the capability of expanding and collapsing the groups when user touches header.

If you are not aware of list view before please refer to this tutorial Android ListView Tutorial.

As seen in the Custom ListView we can use a type of array adapter to control the data displayed in the expandable list view. We will use the BaseExpandableListAdapter to supply and control the data displayed in this tutorial.


In this example I will show you how to implement ExpandableListView.


Let’s get start by creating a project in Eclipse IDE.

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. (I kept my main activity name as

2.  Create a layout file for under res ⇒ layout folder. I named the layout file as activity_main.xml. In this layout i had taken one expandable listview.

3. For expandablelsitview header items create a new xml file naming header.xml  with TextView.

4. Now, for child items create a new xml file naming childs.xml  with TextView.

5. Create a new class naming for ExpandableListView adapter as we done in ListView. In this class we set the header and child items fro expandablelistview by inflating both header and child layout.

6. Now, come to and add the following code. In this class we set the items to adapter and set it to expandablelistview and also we worked on some of its methods list expandgroup, collapsegroup, etc.

7. Now, run the app and you will get the output as shown in video.

Thanks. :)

Download Source Code – >


About the author

I am an Android developer for whom Android is the one and only love. I work as a freelancer which gets me and Android closer. I always love to share my learnings and love to learn from others knowledge too.


Hi, how do I implement the inflate method for different fragments/layouts when clicking on different child items?


    Hi, sorry friend but i didn’t get your question properly. Can you explain it more?


Hello , can u tell me how can i set empty array for one parent item like no child for it and click on parent show toast for it.

    Hi Madhav,

    For this just pass empty array for parent for which you want no child. Then on click event of that parent check the children count by using method getChildrenCount, it will return you 1 or 0 not sure for empty child. On this basis you can show Toast for it.



tutorial is very helpful . but i want to set the arrow at left side . please help thanks . thank u so much for such a good and great tutorials……..

    Hi Ankesh Kumar,

    To implement arrow at left side you have to replace 107-118 code lines from ExpandableListAdapter java class with below one:

    if (isExpanded) {
    header_text.setTypeface(null, Typeface.BOLD);
    header_text.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_up, 0,
    0, 0);
    } else {
    // If group is not expanded then change the text back into normal
    // and change the icon

    header_text.setTypeface(null, Typeface.NORMAL);
    header_text.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_down, 0,
    0, 0);



Is it Possible to add Fragments as a child in ExpandableListView ?
Urgent Please Reply!!!!

    Hi Prabhu,

    Unfortunately you cannot use fragment in ListView, GridView, ExpandableListView and RecyclerView. if you want to use fragment layout that you can use by providing layout as we use in ListView for custom row layout.


Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)