Skip to content
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

Feature Request: Expand+collapse simultaneously #23

Open
ghost opened this issue Aug 7, 2014 · 6 comments
Open

Feature Request: Expand+collapse simultaneously #23

ghost opened this issue Aug 7, 2014 · 6 comments

Comments

@ghost
Copy link

ghost commented Aug 7, 2014

expandAndCollapse animation, for closing the last expanded item while simultaneously opening the next. This would allow the accordion UI type: http://jqueryui.com/accordion/

I believe one of your commenters on your blog also requested this. I will work on it in the meantime as I know you are busy, but I'm not sure I understand your library well enough to implement perfectly.

Ideally in long lists, the position of the clicked expanding item would have a sort of scroll lock for the group header while everything else moved, or the expanding header would smooth scroll to the top of the screen if the expanding group is too large to fit on the screen at once.

@Frequencies
Copy link

list.setOnGroupExpandListener(new ExpandableListView.OnGroupExpandListener() {
int previousGroup = -1;

        @Override
        public void onGroupExpand(int groupPosition) {
            if (groupPosition != previousGroup) {
                list.collapseGroupWithAnimation(previousGroup);
            }
            previousGroup = groupPosition;
        }
    });

@doc-rj
Copy link

doc-rj commented Apr 10, 2015

In combination with my fix for issue #34 , I accomplished the accordion by updating my activity as follows:

private int mLastExpandedGrp = -1;
...
    mGrpListView.setOnGroupClickListener(new OnGroupClickListener() {
        @Override
        public boolean onGroupClick(ExpandableListView parent, View v, int groupPosition, long id) {
            if (mGrpListView.isGroupExpanded(groupPosition)) {
                mGrpListView.collapseGroupWithAnimation(groupPosition);
            } else {
                if (mLastExpandedGrp != groupPosition) {
                    mGrpListView.collapseGroupWithAnimation(mLastExpandedGrp);
                }
                mGrpListView.expandGroupWithAnimation(groupPosition);
                mLastExpandedGrp = groupPosition;
            }
            return true;
        }
    });

@amalChandran
Copy link

@doc-rj there seems to be a flicker before collapsing the previous animation.

@sladek-jan
Copy link

There is also a problem when a group with many items is expanded, then the user scrolls down to another group and expands it. If we simply collapse the group above and expand the new one, list will not scroll up accordingly after the first group is collapsed and user will be looking at about the middle of the newly expanded group (or completely off if it's short).

I fixed this by adding this method to AnimatedExpandableListView

private void restorePositionAfterCollapse(int groupPos) {
        //If collapse was below the current position, we don't move
        if(groupPos >= getFirstVisiblePosition()) {
            return;
        }
        setSelection(getFirstVisiblePosition() - adapter.getChildrenCount(groupPos));
    }

And calling it inside collapseGroupWithAnimation() before returning/starting animation. I also needed to make sure that collapse finishes first and then start the expansion (otherwise the visible position can be wrong). There is a little flicker as I don't address the situation when we see only a half of first visible item (we need to add a little vertical scroll), but this should be easy to fix.

@amalChandran
Copy link

@sladek-jan Nice approach. If only you posted this six months back, would have saved me a lot of headaches..

@sladek-jan
Copy link

sladek-jan commented Jul 12, 2016

Sorry for not being helpful @amalChandran!

In the end, I didn't like how user needed to wait for the collapse to finish. My new approach seems to work well and allows simultaneous collapse and expansion.
I uploaded the code to pastebin as line breaks in code don't seem to work here.

[(http://pastebin.com/0jJ5Lbz0)]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants