繁体   English   中英

如何在ExpandableListView中隐藏特定组的子项?

[英]How to hide child items for a particular group in ExpandableListView?

我的ExpandableListView始终具有特定组的单个子级。 对于某些组,我想隐藏子项,但是我希望该组仍然可单击(单击后的每个组项都会更改其布局)。 那么,应该从getChildView为这些组返回什么?

覆盖getChildrenCount ,对于想要的组,返回0,就好像它们没有孩子一样。 他们仍然将是可点击的。

@Override
public int getChildrenCount(int groupPosition) {
    if (groupPosition == 1) {
        return 0;
    } else {
        return super.getChildrenCount(groupPosition);
    }
}

这是我的想法,代码未经过测试

public view getChildView(int groupPosition, int ChildPosition, boolean b, View view, ViewGroup viewGroup){
if(!groupPostion)//for the group you dont want the layout to be displayed
v=your custom view for the child items.//or if you know the exact position define it like 
//if or use switch (groupPosition==something){v.setVisibility(View.GONE)}
return v;
}

您需要调用crashGroup() 同样在您的构造函数中,您需要您的ExpandableListView

public class YourExapandableAdapter extends BaseExpandableListAdapter {

    private Context mContext;
    ExpandableListView mExpandableListView;
    int mLastExpandedGroupPosition = -1;

    public YourExapandableAdapter(Context context, ExpandableListView expandableListView) {
            mContext = context;
            mExpandableListView = expandableListView;
    }

    @Override
    public void onGroupExpanded(int groupPosition) {
        super.onGroupExpanded(groupPosition);
        if(groupPosition != mLastExpandedGroupPosition){
                mExpandableListView.collapseGroup(mLastExpandedGroupPosition);
        }

        mLastExpandedGroupPosition = groupPosition;
    }

在这种情况下,我隐藏了最后一个组,但是您可以当前组或任何您想要的组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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