Question

I'm currently learning about expandable listview in android. How to handle expansion of list? That is if the header doesn't have any children, I don't want it to expand. How to do this? I thought of not adding that header to headerList, but I wan to display it and handle the expansion depending upon the children. Is there anyway to do it?

Was it helpful?

Solution

IF there is no child in the particular parent, then it won't expand (because there is nothing to show).

If your question is how to hide the group indicator when there is no child present, then put the following snippet inside getGroupView() :

if ( getChildrenCount( groupPosition ) == 0 ) {
       indicator.setVisibility( View.INVISIBLE );
    } 
else {
       indicator.setVisibility( View.VISIBLE );
       indicator.setImageResource( isExpanded ? R.drawable.group_expanded : R.drawable.group_closed );
    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top