android-advancedrecyclerview icon indicating copy to clipboard operation
android-advancedrecyclerview copied to clipboard

Can ExpandableRecyclerViewWrapperAdapter only one group expandable?

Open jacklai24 opened this issue 8 years ago • 6 comments

I want to modify ExpandableRecyclerViewWrapperAdapter let it one group can expandable. How to do? Thank you.

jacklai24 avatar Jul 13 '17 10:07 jacklai24

I try to modify like this but not success. Please help me how to do. Thank you.

ExpandableRecyclerViewWrapperAdapter.java Line 701.

if (expand) { if (mPreGroupPosition != -1) { mPositionTranslator.collapseGroup(mPreGroupPosition); } expandGroup(groupPosition, true, null); } else { collapseGroup(groupPosition, true, null); } mPreGroupPosition = groupPosition;

jacklai24 avatar Jul 14 '17 13:07 jacklai24

java.lang.IllegalArgumentException: Called attach on a child which is not detached: ViewHolder{3dbc6e98 position=1 id=0, oldPos=-1, pLpos:-1 not recyclable(1)}

I got this error message. Please help me. Thank you.

jacklai24 avatar Jul 22 '17 08:07 jacklai24

Its not clear what you want to achieve. I assume you want one group can be opened only. Override the method:

@Override
public boolean onCheckCanExpandOrCollapseGroup(GroupViewHolder holder, int groupPosition, int x, int y, boolean expand) {

}

zeroarst avatar Jul 22 '17 09:07 zeroarst

I want only one group expand at once. When I click another group, this group expand and previous group collapse.

jacklai24 avatar Jul 22 '17 13:07 jacklai24

@jacklai24 Hi. Sorry for the very late response 🙇

I want only one group expand at once. When I click another group, this group expand and previous group collapse.

Okay, but I think you do not need to modify the internal of this library. Try the following code snippet, it may work as you need.

static class MyAdapter extends AbstractExpandableItemAdapter<...> implements View.OnClickListener {
    RecyclerViewExpandableItemManager mExpandableManager;

    public MyAdapter(RecyclerViewExpandableItemManager expandableManager) {
        setHasStableIds(true);
        mExpandableManager = expandableManager;
    }

    @Override
    public MyGroupViewHolder onCreateGroupViewHolder(ViewGroup parent, int viewType) {
        View v = LayoutInflater.from(parent.getContext()).inflate(..., parent, false);
        v.setOnClickListener(this);  // <- Set click event listener
        return new MyGroupViewHolder(v);
    }

    @Override
    public boolean onCheckCanExpandOrCollapseGroup(MyGroupViewHolder holder, int groupPosition, int x, int y, boolean expand) {
        return false;   // <- Do not expand automatically on clicked a group item. Instead, we handle click event manually.
    }

    @Override
    public void onClick(View view) {
        RecyclerView rv = RecyclerViewAdapterUtils.getParentRecyclerView(view);
        RecyclerView.ViewHolder vh = rv.findContainingViewHolder(view);

        long packedPosition = mExpandableManager.getExpandablePosition(vh.getAdapterPosition());
        int groupPosition = RecyclerViewExpandableItemManager.getPackedPositionGroup(packedPosition);

        if (mExpandableManager.isGroupExpanded(groupPosition)) {
            // collapse the clicked group
            mExpandableManager.collapseGroup(groupPosition);
        } else {
            // expand the clicked group and collapse others
            mExpandableManager.collapseAll();
            mExpandableManager.expandGroup(groupPosition);
        }
    }
}

h6ah4i avatar Sep 18 '17 13:09 h6ah4i

hi. As I said, I expanded one item when I clicked it. However, an error occurred and it crashed. payload was null. I used Kotlin language. When I used it in Java, there was no problem, but because it was a Kotlin project, I used Kotlin, but an error occurred. I hope you can help

ExpandableDraggableSwipeableExampleFragment

mExpandableManager.collapseAll(); mExpandableManager.expandGroup(groupPosition);

nuribabo avatar Apr 16 '22 15:04 nuribabo