当其中没有 childView 时,我想删除 ExpandableListView 的 groupView

I want to remove the groupView of an ExpandableListView when there is no childView in it

原谅我的提问方式和我的英文。当没有 childView 时,我想删除 groupViewExpandableListView 。我明白了可扩展的 childView 通过使用 retrofit 2。 请耐心等待我,因为我有一点开发技巧android :)

这是我的 ExpandableListView 适配器 代码

public class ExpandableListAdapter extends BaseExpandableListAdapter {
private Context _context;
private List<Headers> _listDataHeader; 
private HashMap<Headers, List<FixturesObject>> _listDataChild;

public ExpandableListAdapter(Context context, List<Headers> listDataHeader,
                             HashMap<Headers, List<FixturesObject>> listChildData) {
    this._context = context;
    this._listDataHeader = listDataHeader;
    this._listDataChild = listChildData;
}
@Override
public int getGroupCount() {
    return this._listDataHeader.size();
}

@Override
public int getChildrenCount(int groupPosition) {
    return this._listDataChild.get(this._listDataHeader.get(groupPosition))
            .size();
}

@Override
public Object getGroup(int groupPosition) {
    return this._listDataHeader.get(groupPosition);
}

@Override
public Object getChild(int groupPosition, int childPosition) {

    return this._listDataChild.get(this._listDataHeader.get(groupPosition))
            .get(childPosition);
}


@Override
public long getGroupId(int groupPosition) {
        return groupPosition;
}

@Override
public long getChildId(int groupPosition, int childPosition) {
    return childPosition;
}

@Override
public boolean hasStableIds() {
    return false;
}

@Override
public View getGroupView(int groupPosition, boolean isExpanded, View convertView, ViewGroup parent) {

    Headers headers = (Headers) getGroup(groupPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_group, null);
    }

    TextView lblListHeader = (TextView) convertView.findViewById(R.id.textHeader);
    lblListHeader.setTypeface(null, Typeface.BOLD);
    ImageView imageView = (ImageView) convertView.findViewById(R.id.image);


        lblListHeader.setText(headers.getNameLeague());
        imageView.setImageResource(headers.getImageID());
    return convertView;
}

@Override
public View getChildView(int groupPosition, int childPosition, boolean isLastChild, View convertView, ViewGroup parent) {
    FixturesObject fixturesObject =(FixturesObject) getChild(groupPosition,childPosition);
    if (convertView == null) {
        LayoutInflater infalInflater = (LayoutInflater) this._context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = infalInflater.inflate(R.layout.list_item, null);
    }
    TextView HomeTeamName = (TextView) convertView.findViewById(R.id.home_team_name);

    HomeTeamName.setText(fixturesObject.getMatchHometeamName());
    return convertView;
}

@Override
public boolean isChildSelectable(int groupPosition, int childPosition) {
    return true;
}
}

一种方法是将 getGroupView 编辑为 return 高度为 0dp 的空 FrameLayout getChildrenCount( groupPosition ) == 0,如果它有子项则使用当前代码。