Simple Expandable List Example

This example shows how to create Expandable list using simple default adapter.


1.) Create a new project by File-> New -> Android Project name it SimpleExpandableListExample.

2.) Run for output.


1.) Create a project named SimpleExpandableListExample and set the information as stated in the image.

Build Target: Android 2.3.3
Application Name: SimpleExpandableListExample
Package Name: com.example
Activity Name: SimpleExpandableListExampleActivity
Min SDK Version: 10

2.) Open file and write following code there:


package com.example;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import android.os.Bundle;
import android.widget.ExpandableListAdapter;
import android.widget.SimpleExpandableListAdapter;

public class SimpleExpandableListExampleActivity extends ExpandableListActivity {
private static final String NAME = "NAME";
private static final String IS_EVEN = "IS_EVEN";

private ExpandableListAdapter mAdapter;

public void onCreate(Bundle savedInstanceState) {

List<Map<String, String>> groupData = new ArrayList<Map<String, String>>();
List<List<Map<String, String>>> childData = new ArrayList<List<Map<String, String>>>();
for (int i = 0; i < 20; i++) {
Map<String, String> curGroupMap = new HashMap<String, String>();
curGroupMap.put(NAME, "Item " + i);
curGroupMap.put(IS_EVEN, (i % 2 == 0) ? "This group is even" : "This group is odd");

List<Map<String, String>> children = new ArrayList<Map<String, String>>();
for (int j = 0; j < 5; j++) {
Map<String, String> curChildMap = new HashMap<String, String>();
// curChildMap.put(NAME, "Child " + j);
curChildMap.put(IS_EVEN, (j % 2 == 0) ? "Hello " + j: "Good Morning "+ j);

// Set up our adapter
mAdapter = new SimpleExpandableListAdapter(
new String[] { NAME, IS_EVEN },
new int[] {, },
new String[] { NAME, IS_EVEN },
new int[] {, }




3.) Compile and build the project.

Leave a Comment:

Jose says May 27, 2012


I need that my class extends also from Activity, in my View appears more data, no only an ExpandableListActivity. How could I do this?


ariel says September 22, 2012

Muchas gracias… de gran utilidad 🙂

Michael says October 25, 2012

I’ve read hundreds (if not thousands) of tutorials and examples while developing Android applications, but I never wrote any comment if anything helped me – yes I will change that about myself.

After realizing that this saved my damned day I just wanted to say: Thank you!

Sagar says November 7, 2012

Is it possible to open expandableList on a button click in a activity ? I did succeed but list is hidden and not shown completely. For example like drop down list.

-coffee- says May 26, 2013

Thanks a lot! One question: where will the strings “This group is even” and “This group is odd” go?

Gonzalo says August 7, 2013

At last, a simple example of an expandable list, it is difficult to find them.
Just a couple of things:
* You are using a simple_expandable_list_item_1 for the main list, which have just one TextView, but you use two text for each item of the main list; so, the second one(key=IS_EVEN), it is not used (This group is even/odd).
* Secondly, you use a simple_expandable_list_item_2 for the children, these are the lists that are inside the main list; but you just put of them inside the children the list, the other is simply commented (// curChildMap.put(NAME, “Child ” + j)). I suppose you just want to use one of them, and this is because it appear a blank line inside each child item.
Anyway, thank you for your example.

Shashi Kumar says September 24, 2013

Best tutorial I’ve ever come across.

Hats off to you. Thank you.

Add Your Reply