简体   繁体   中英

Hide group with no child - ExpandableListView

I want to hide the whole group from ExpandableListView if it has no child(s). I've tried to use this in the 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 is not working I still see the indicator (the text is removed) and a empty space.

Also I've tried this:

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

That's working but when I try to open another group I get a java.lang.NullPointerException .

Is it possible to hide group(s) from ExpandableListView if it has no child(s)?

您必须在适配器中实现datamodel以便它允许删除,然后在删除它之后,在适配器上设置invoke notifyDataSetChanged()。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM