Friday, January 27, 2012

How to use ExpandableListView

Working with ExpandableListView is very complex, so to make things simpler I will explain you how to use this ListView in few simple steps. This example will display 3 category of vehicles in a ExpandableList.

Firstly we will create the Layout files for Main Activity, GroupView and ChildView Layout.
MainActivity: main.xml


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <ExpandableListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="fill_parent" >
    </ExpandableListView>
</LinearLayout>