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

the OnItemExpandCollapseListener not work! #100

Closed
chenchongyu opened this issue Jul 3, 2015 · 5 comments
Closed

the OnItemExpandCollapseListener not work! #100

chenchongyu opened this issue Jul 3, 2015 · 5 comments

Comments

@chenchongyu
Copy link

I want to change the icon of the toggleButton when I click the btn.So I set a OnItemExpandCollapseListener on the SlideExpandableListAdapter,but not work. When I debug,the listener is null.Why?

@tjerkw tjerkw closed this as completed Aug 5, 2015
@lorenzos
Copy link

Same problem here. The listener is null, and I can't get why! Why is it closed?

@lorenzos
Copy link

Ok, I think I got it. In SlideExpandableListView.java line 44 a new SlideExpandableListAdapter is initialized, but instead documentation says that we are supposed to instantiate and pass it.

In README.md line 93:

Wrap your ListAdapter
list.setAdapter(new SlideExpandableListAdapter(adapter, ...));

But in code:

public void setAdapter(ListAdapter adapter) {
    this.adapter = new SlideExpandableListAdapter(adapter);
    super.setAdapter(this.adapter);
}

Basically our custom SlideExpandableListAdapter, the one with our expand/collapse listener, is wrapper into another, new SlideExpandableListAdapter, which has no listener obviously.

This is a major issue in my opinion. If you think about it, the list adapter is wrapped two times with no reason at all. We should change the code (i.e. assigning the SlideExpandableListAdapter directly, without wrapping it) or the documentation (i.e. it should be said that we must pass the normal list adapter, not the SlideExpandableListAdapter, but then provide a getSlideExpandableListAdapter() method, so we can grab it and set our listener).

I'm ready to provide a pull request, but there's a choice to be made, and it must be made by @tjerkw

@MarcoMirisola
Copy link

Hi @lorenzos could you please show us the solution? I can't figure out how to resolve this issue.
Thanks

@lorenzos
Copy link

lorenzos commented Jul 28, 2016

Hi @MarcoMirisola

I didn't provide a pull request because I proposed two solutions that work both, but are different in architecture. I was waiting for a reply by @tjerkw on which is its favourite, and then I forgot this at all.

First proposed solution

Remove both the setAdapter methods in the SlideExpandableListView class and replace them with:

public void setAdapter(SlideExpandableListAdapter adapter) {
    this.adapter = adapter;
    super.setAdapter(this.adapter);
}

Second proposed solution

If I remeber well, I ended up chosing this one.
Add the following method in the SlideExpandableListView class:

public SlideExpandableListAdapter getSlideExpandableListAdapter() {
    return adapter;
}

Change the setup code in your application from:

list.setAdapter(new SlideExpandableListAdapter(adapter, ...));

To:

list.setAdapter(adapter, ...);

Now, when you want to attach the listener, you do on it the instance returned by the new method, not on your original adapter:

list.getSlideExpandableListAdapter().setItemExpandCollapseListener(...)

@MarcoMirisola
Copy link

Thanks @lorenzos! I've used your second solution and it works perfectly. I hope @tjerkw replays you.

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