ExpandableListView with CheckedTextView


I was implementing a settings list activity with CheckedTextView and I found out that Android’s ExpandableListView is a handy component to display some hierarchical data. However in my case there was one weakness. You can not see which items are selected when a parent group is collapsed. I wanted to display the text of selected child items in the parent view. My biggest problem was that I couldn’t reach the parent view in reliably way when child item was clicked.

I tried to search from the internets are there any solutions ready, but I found nothing there (or I used wrong search terms). As earlier I made my own solution.

My ExpandableListView solution is based on this tutorial. 

I solved parent view issue by setting unique tag to parent view in Adapter class.

//in this method you must set the text to see the parent/group on the list
public View getGroupView(int i, boolean b, View view, ViewGroup viewGroup) {

if (view == null) {
view = inflater.inflate(R.layout.settings_list_item_parent, viewGroup,false);
// set category name as tag so view can be found view later



Based on that tag I can find parent view later when child item is clicked.

public boolean onChildClick(ExpandableListView parent, View v,
int groupPosition, int childPosition, long id) {

CheckedTextView checkbox = (CheckedTextView)v.findViewById(R.id.list_item_text_child);

// find parent view by tag
View parentView = categoriesList.findViewWithTag(categories.get(groupPosition).name);


One nice feature that I have used in my ExpandableListView is autocollapse feature that I found here.

Get the full source code here: https://github.com/nevalla/expandablelistview-demo