代码之家  ›  专栏  ›  技术社区  ›  user9317657

如果ExpandableListView中没有子视图,我想删除它的groupView

  •  0
  • user9317657  · 技术社区  · 6 年前

    请原谅我的提问方式和我的英语。我想删除 组视图 我的 多级列表 当没有 儿童视图 为了它。我得到我的 可扩展儿童视图 通过使用 改装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;
    }
    }
    
    1 回复  |  直到 6 年前
        1
  •  0
  •   cwbowron    6 年前

    一种方法是编辑 getGroupView 若要返回高度为0dp的空FrameLayout,请执行以下操作: getChildrenCount( groupPosition ) == 0 如果有子项,则使用当前代码。