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

How to expand one item of an ExpandingList at a time, thus opening a another item would close the previously opened item? #8

Open
SachinTanpure opened this issue Feb 10, 2017 · 1 comment

Comments

@SachinTanpure
Copy link

No description provided.

@diegodobelo
Copy link
Owner

diegodobelo commented Feb 10, 2017

Hi @SachinTanpure . You can store the last expanded item and call toggleExpanded() method when other item is expanded.
Something like this:

private ExpandingItem mExpandedItem;
...

item.setStateChangedListener(new ExpandingItem.OnItemStateChanged() {
                @Override
                public void itemCollapseStateChanged(boolean expanded) {
                    if (mExpandedItem != null && mExpandedItem.isExpanded()) {
                        mExpandedItem.toggleExpanded();
                    }
                    if (expanded) {
                        mExpandedItem = item;
                    } else if (mExpandedItem.equals(item)) {
                        mExpandedItem = null;
                    }
                }
            });

If you check the example code in this repository you can put the code above in the line 96 of MainActivity.java

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

2 participants