android-advancedrecyclerview
android-advancedrecyclerview copied to clipboard
Can ExpandableRecyclerViewWrapperAdapter only one group expandable?
I want to modify ExpandableRecyclerViewWrapperAdapter let it one group can expandable. How to do? Thank you.
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;
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.
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) {
}
I want only one group expand at once. When I click another group, this group expand and previous group collapse.
@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);
}
}
}
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);