简体   繁体   中英

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

Forgive me on my question way and my English . I want to remove the groupView of my ExpandableListView when there is no childView for it .I get my Expandedable childView through using retrofit 2 . Please be patient with me because I have a little skills in developing android :)

Here is my ExpandableListView Adapter code

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以在getChildrenCount( groupPosition ) == 0返回高度为0dp的空FrameLayout,并在有子代的情况下使用当前代码。

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