-
Notifications
You must be signed in to change notification settings - Fork 293
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
Adjusting the Visibility Last Group #156
Comments
I have the same question, any workarounds would be awesome, Thanks |
This has been at the back of my mind as well, some related questions:
My opinions right now, which may change as I talk with more people on this:
Haven't started to look into how to do this all yet, I think it will cause some custom code based on the type of LayoutManager. This may be possible without changes to the library, maybe if you listen for expand events, see when an expand happens to the last item, and if so scroll down to the correct position/item. This might be preferred rather than changes to the library so I welcome opinions there as well (and if it is feasible). |
I'm using a coarse approach... Simply, I use the RecyclerView.smoothScrollToPosition in the onListItemExpanded listener method. With this snipper, I manage to close all the parents, except the one I'm expanding, and scroll only if children are out of the screen. @Override
public void onListItemExpanded(int position) {
List<? extends ParentListItem> parentItemList = adapter.getParentItemList();
for (int i = 0; i < parentItemList.size(); i++) {
if (i != position) {
adapter.collapseParent(i);
}
}
listView.smoothScrollToPosition(position + parentItemList.get(position).getChildItemList().size());
} |
Slightly changing @falkontre proposed solution made it work for me. Put the following code inside the adapter. int lastPos = -1;
@Override
public void onParentListItemExpanded(int position) {
List<? extends ParentListItem> parentItemList = this.getParentItemList();
collapseAllParents();
int finalPos = position;
if (lastPos != -1 && lastPos < position) {
finalPos = position - parentItemList.get(lastPos).getChildItemList().size();
}
expandParent(finalPos);
mRecyclerView.smoothScrollToPosition(finalPos);
lastPos = position;
} |
I do not think this will work.
Use:
|
I have a question. When I use the above code (by ankit-agg and also by falkontre) inside adapter. And it shows recycler view object undefined. Rightly because we cannot access recyclerview object is not passed inside the adapter. So is there any way to work around with it? |
@Tier5 You won't need to pass a reference to the RecyclerView into its Adapter. Instead, the adapter is attached to a RecyclerView, and you can obtain a reference to it in |
This worked for me. |
I fix this issue by writing custom LayoutManager
|
@isamorodov, thanks, working beautifully. |
On point 4, I doubt it. User expanded to see the sub-contents, so it should scroll. |
If Last Group Header is at the bottom of the list, if we click on that item header, it will expand the child item but we need to manually scroll to see the last item. Any workaround is possible, like when we expand the last item, it should scroll to show the content below the header...
The text was updated successfully, but these errors were encountered: