From Developer.android.com: “A view that shows items in a vertically scrolling two-level list. This differs from the ListView by allowing two levels: groups which can individually be expanded to show its children. The items come from the ExpandableListAdapter associated with this view”
In this tutorial, we show you how to create a custom ExpandableListView with some images, texts... We want to make some groups of car and customize them with image, text and a checkbox. In each group, we will contain a few different cars, in particular each children row has to contain: an image and the name of the car.
Here is a result of this tutorial:
This project is developed in Eclipse 4.2.0.
1. Make application interface: The main layout of this app demo have a text view, a button and an expandable list view.
For android:groupIndicator of expandable list, create res/drawable/group_indicator_selector.xml and parse all xml content below:
Now is the time we customize our expandable list view by create the layout for each group item and child item of it:
For group item:
Customize checkbox in group item with android:button attribute by make a checkbox_selector.xml in drawable folder:
For children item:
Thus we have completed the design of the interface. Now begin make some codes.
2.1. We start by creating the SampleExpandableListAdapter for ExpandableListView
2.2. Create view holder class to hold all component of group item or child item
2.3. Then in the main activity, set adapter for expandable list view and when user click on the button will show all groups on expandable list view has checked on checkbox by Toast Message.
3.1. Run application
3.2. Click on a button
You can download all source codes of this tutorial from here.