Android Expandable ListView Tutorial


Greeting appears here to Android Expandable ListView. It has the capability to collapsed individually when a user touches the header. In this post, I will implement a complete example of an expandable listView look like this.Alt tag android expendable listview


“It will good to cover my previous articles before this. It helps to learn more about Android development. In which I explained.”

Android Expandable ListView

  • Android Expandable ListView is a view that shows the Item vertically scaling of the two-way list.
  •  Expandable ListView differs from listView by adding two levels.
  • The expandable list divided into groups.
  • The group is individually expandable to show the children.
  • The expendable listview usage for group data.
  • The following are the important method that is used in expendable listView.
Method Description
getGroupView() It returns a view of the group header.
getChildView() It returns a view of the child item.
set groupIndicator(Drawable) This is corresponding to XML attributes. SetGroupIndicator (Drawable) indicated to expand or empty. If the grope is empty than an empty state is set. If the grope is expanded than expanded state is set.
setChildIndicator(Drawable) This is corresponding to XML attributes. setChildIndicator (Drawable) it represents the current state.

Let’s begin :

  • Modify the string.XML.
  • Create a main_activity.XML.
  • Layout for expendable listView.
  • Define the Adapter class.
  • MainActivity.
  • Run the application.

Step1) Modify the string.XML

  • Open <res> click on <values>  than open <string.xml>
  • <Paste the following code>
  • File:string.xml

Step2) Create a main_activity.XML

This code contains an expandable listview. In a ListView, we had created only two layouts one for listView other for single_row. But in expendable listView, we will create three layouts one for expandable listview other for child view that is collapsed one remaining which is single_row.

Step3) Layout of expendable listView for single_row

In a single_row Layout, and Inflator is used which converted XML appearance into java.  They are two common methods are used for that.

Step4) Layout of expendable listView for child

The following is the child_Layout for expandable listView that is collapsed.

Step5) Define the Adapter class

Step6) MainActivity

Run the application and see the amazing output. The output contains the expendable listView which is collapsed and shows the child item.

Wrap up

In this section, we had learned the android expendable listView. We had created three layouts one for expendable listview 2nd for single row and 3rd for the child.  The data source for the expandable listview we used in string.XML. I hope you got the idea. for more about it.