Hide group without child - ExpandableListView

I want to hide the whole group from ExpandableListView if it does not have children. I tried using this in public View getGroupView :

 if (getChildrenCount(groupPosition) == 0) { convertView.setVisibility(View.INVISIBLE); lblListHeader.setVisibility(View.INVISIBLE); } else { convertView.setVisibility(View.VISIBLE); lblListHeader.setVisibility(View.VISIBLE); } 

But that does not work. I still see the indicator (text deleted) and empty space.

Also I tried this:

 if (getChildrenCount(groupPosition) == 0) { convertView = layoutInflater.inflate(R.layout.blank_layout, null); } 

This works, but when I try to open another group, I get java.lang.NullPointerException .

Is it possible to hide a group (s) from an ExpandableListView if it has no children?

+4
source share
1 answer

You need to implement the datamodel in the adapter so that it allows deletion, and then as soon as you delete it, you set invokeDataSetChanged () on the adapter.

+1
source

Source: https://habr.com/ru/post/1502436/


All Articles