
The activity_main.xml layout consists of an ExpandableListView in a RelativeLayout as shown below : activity_main.xml
A CustomExpandableListAdapter which provides the MainActivity with the data from the ExpandableListDataPump class/li>. An ExpandableListDataPump which represents a random data in a List and maps the child item data to the respective group headers using a HashMap. A MainActivity that shows the layout with the ExpandableListView. ExpandableListView.OnGroupExpandListener : It is used to notify when a group is expandedĪndroid ExpandableListView Project Structure. ExpandableListView.OnGroupCollapseListener : It is used for notifying when a group is collapsed. ExpandableListView.OnGroupClickListener : This is overridden to implement the callback method that’s invoked when a group header in the expanded list is clicked.
ExpandableListView.OnChildClickListener : This is overridden to implement the callback method that’s invoked when a child in the expanded list is clicked. The notable interfaces that are implemented by this class are given below : getChildView() : It returns view for list child item. getGroupView() : It returns view for the list group header. If the group is expanded, the state state_expanded will be set If the group is empty, the state state_empty will be set. setGroupIndicator(Drawable) : An indicator is drawn besides the group representing its state i.e. If the child is the last child for a group, the state state_last will be set setChildIndicator(Drawable) : This is used to show an indicator besides each item representing the current state.
Following are some important methods that are used by this class : ExpandableListViewAdapter in android loads the data into the items associated with this view. It differs from a ListView by allowing two levels which are groups that can be easily expanded and collapsed by touching to view and their respective children items.
Android ExpandableListViewĪndroid ExpandableListView is a view that shows items in a vertically scrolling two-level list. It’s sort of menu and submenus in a Android ListView. In this tutorial we’ll implement an ExpandableListView which is used to group list data by categories. Welcome to Android ExpandableListView Example Tutorial.