我的ExpandableListView
一直是特定群体的单身儿童。对于某些群组,我希望隐藏子项,但我希望群组仍然可以点击(点击后每个群组项目都会更改它的布局)。那么应该从getChildView
?
答案 0 :(得分:0)
覆盖getChildrenCount
并为您想要的群组返回0,就好像他们没有孩子一样。它们仍然可以点击。
@Override
public int getChildrenCount(int groupPosition) {
if (groupPosition == 1) {
return 0;
} else {
return super.getChildrenCount(groupPosition);
}
}
答案 1 :(得分:0)
以下是我认为,代码未经过测试
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;
}
答案 2 :(得分:0)
您需要致电collapseGroup()。同样在您的构造函数中,您需要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;
}
在这种情况下,我隐藏了最后一组,但您可以使用当前组或任何您想要的组。