New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Expand Problem] : How to lock expanding of a specific group using onBindGroupViewHolder? #302

soyuz7KOK opened this Issue Aug 29, 2016 · 2 comments


None yet
2 participants

soyuz7KOK commented Aug 29, 2016


i want to lock expanding of some specific groups (ie. if the group has only one child) and want to set the groups other click event listener in my custom ExpandableItemAdapter class.

i think i need to implement in onBindGoupViewHolder, but how?


This comment has been minimized.


h6ah4i commented Aug 29, 2016

@soyuz7KOK Hi.

i want to lock expanding of some specific groups

If you want to custom click event handling, make the onCheckCanExpandOrCollapseGroup() method always returns false, then set click listener in onCreateGroupViewHolder() (or in onBindGroupViewHolder()). In the click event handler, collapseGroup() / expandGroup() methods can be used to control the group's expanded state.

public boolean onCheckCanExpandOrCollapseGroup(MyGroupViewHolder holder, int groupPosition, int x, int y, boolean expand) {
    return false;

public MyGroupViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
    final LayoutInflater inflater = LayoutInflater.from(parent.getContext());
    final View v = inflater.inflate(..., parent, false);
    MyGroupViewHolder vh = new MyGroupViewHolder(v);
    return vh;

public void onClick(View v) {
    RecyclerView.ViewHolder vh = RecyclerViewAdapterUtils.getViewHolder(v);
    int flatPosition = vh.getAdapterPosition();

    if (flatPosition == RecyclerView.NO_POSITION) {

    long expandablePosition = mExpandableItemManager.getExpandablePosition(flatPosition);
    int groupPosition = RecyclerViewExpandableItemManager.getPackedPositionGroup(expandablePosition);
    int childPosition = RecyclerViewExpandableItemManager.getPackedPositionChild(expandablePosition);

    // toggle expanded/collapsed
    if (mExpandableItemManager.isGroupExpanded(groupPosition)) {
    } else {

Please refer to the following adapter implementation in the demo app for actual usages;

Related issue

@h6ah4i h6ah4i added the question label Aug 29, 2016


This comment has been minimized.

soyuz7KOK commented Aug 30, 2016

I could realize all i wanted!
Thanks for helpful advice:)

@soyuz7KOK soyuz7KOK closed this Aug 30, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment