Open shanums opened 7 years ago
This works for me.
mRvExpItemMgr.expandGroup(groupPosition);
final int adapterPos = mRvExpItemMgr.getFlatPosition(RecyclerViewExpandableItemManager.getPackedPositionForChild(groupPostion, childPosition));
mRv.smoothScrollToPosition(adapterPos);
@shanums Hi.
If I click on the last visible group the child of the particular group is not visible unless and until if we scroll the list up. Is there a way to scroll the list up automatically when we click on a group..
Please check the "Expandable (Basic)" demo implementation. It demonstrates that the automatic scrolling to fit within the screen. (Also, you can use zeroarst's answer 😉)
@Override
public void onGroupExpand(int groupPosition, boolean fromUser) {
if (fromUser) {
adjustScrollPositionOnGroupExpanded(groupPosition);
}
}
private void adjustScrollPositionOnGroupExpanded(int groupPosition) {
int childItemHeight = getActivity().getResources().getDimensionPixelSize(R.dimen.list_item_height);
int topMargin = (int) (getActivity().getResources().getDisplayMetrics().density * 16); // top-spacing: 16dp
int bottomMargin = topMargin; // bottom-spacing: 16dp
mRecyclerViewExpandableItemManager.scrollToGroup(groupPosition, childItemHeight, topMargin, bottomMargin);
}
I have two buttons in child view,Say Button1,Button2 When I click on Button1 I'm changing the color of Button2. But my problem is that, if I change the color of Button2 of group1. some of the other group's Button2's color is also getting changed.I have written the button click listener in onBindChildViewHolder. Could you please tell me why is this happening.?
I guess there are two possibilities;
Cause 1. Item views are reused by RecyclerView
Since RecyclerView
reuses item views by nature, you need follow its coding manner.
onBindViewHolder()
(onBindChildViewHolder()
in this case) call.ex.)
/*** BAD ***/
void onBindChildViewHolder(MyChildViewHolder holder,
final int groupPosition, final int childPosition, int viewType) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
void onClick(View v) {
// NOTE: captured variables here may be out of sync with current data set
ChildItem = dataSet.get(groupPosition).children(childPosition);
...
}
});
}
/*** GOOD ***/
void onBindChildViewHolder(MyChildViewHolder holder,
int groupPosition, int childPosition, int viewType) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
void onClick(View v) {
RecyclerView rv = RecyclerViewAdapterUtils.getParentRecyclerView(v);
RecyclerView.ViewHolder vh = rv.findContainingViewHolder(v);
int flatPosition = vh.getAdapterPosition();
if (flatPosition == RecyclerView.NO_POSITION) {
return;
}
long expandablePosition = mExpandableItemManager.getExpandablePosition(flatPosition);
int groupPosition = RecyclerViewExpandableItemManager.getPackedPositionGroup(expandablePosition);
int childPosition = RecyclerViewExpandableItemManager.getPackedPositionChild(expandablePosition);
ChildItem = dataSet.get(groupPosition).children(childPosition);
...
}
});
}
Cause 2. Drawables are sharing its state internally
Use [Drawable.mutate()
](https://developer.android.com/reference/android/graphics/drawable/Drawable.html#mutate()) to avoid the problem. Please see the following StackOverflow post for more details.
i have same issue, i tried all these solutions but still i have this issue. Is there any other solution for this problem?
holder.itemView.setOnClickListener(new View.OnClickListener() {
void onClick(View v) {
RecyclerView rv = RecyclerViewAdapterUtils.getParentRecyclerView(v);
RecyclerView.ViewHolder vh = rv.findContainingViewHolder(v);
int flatPosition = vh.getAdapterPosition();
if (flatPosition == RecyclerView.NO_POSITION) {
return;
}
long expandablePosition = mExpandableItemManager.getExpandablePosition(flatPosition);
int groupPosition = RecyclerViewExpandableItemManager.getPackedPositionGroup(expandablePosition);
int childPosition = RecyclerViewExpandableItemManager.getPackedPositionChild(expandablePosition);
ChildItem = dataSet.get(groupPosition).children(childPosition);
...
}
});
Can you please explain to me what "dataSet" means in this context? What is it? And what is "ChildItem" declared as?
Hi Thanks a lot for an awesome library. I made an app using this library. which works pretty well. Im facing some difficulty to implement the following things. Any help will be appreciated.
If I click on the last visible group the child of the particular group is not visible unless and until if we scroll the list up. Is there a way to scroll the list up automatically when we click on a group..?
I have two buttons in child view,Say Button1,Button2 When I click on Button1 I'm changing the color of Button2. But my problem is that, if I change the color of Button2 of group1. some of the other group's Button2's color is also getting changed.I have written the button click listener in onBindChildViewHolder. Could you please tell me why is this happening.?
Thank you.!