tjerkw / Android-SlideExpandableListView

A better ExpandableListView, with animated expandable views for each list item
Apache License 2.0
1.98k stars 741 forks source link

expandable_toggle_button override OnClickListener #35

Open ghost opened 11 years ago

ghost commented 11 years ago

I want to do something when the expandable_toggle_button is clicked, how can I override its OnClickListener?

alepage commented 11 years ago

I'm interested to do that too and I have found no way. An answer will be very appreciated :)

ghost commented 11 years ago

Well, I didn't find anyway except passing my Activity object in the constructor and calling a method in my Activity in the method private void enableFor(final View button, final View target,final int position) in the AbstractSlideExpandableListAdapter where you can find a clicklistener for the button in this method.

ofdrykkja commented 11 years ago

you can perform that by extending button class:

public class ToggleExpandableMenuButton extends ImageButton {

    private ToggleListener listener;

    public ToggleExpandableMenuButton(Context context) {
        super(context);
    }

    public ToggleExpandableMenuButton(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ToggleExpandableMenuButton(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
    }

    @Override
    public boolean performClick() {
        if (listener != null) {
            listener.toggle();
        }
        return super.performClick();
    }

    public void setToggleListener(ToggleListener listener) {
        this.listener = listener;
    }

    public static interface ToggleListener {
        public void toggle();
    }
}
supareek commented 10 years ago

I tried using SlideExpandableListAdapter.setItemExpandCollapseListener(...) passing a new ItemExpandCollapseListener. But it did not work.

The listener is coming as null in the SlideExpandableListAdapter.notifiyExpandCollapseListener() even though I had set it as above.

This is how I am setting the adapter in the list view listView.setAdapter(new SlideExpandableListAdapter(adapter, R.id.expand_toggle_button, R.id.expandable));

Any ideas @tjerkw , why the listener is coming as null? Is it because the setAdapter is wrapping the adapter again?

robertotucci commented 10 years ago

I've tried this code but doesn't works;

new AbstractSlideExpandableListAdapter.OnItemExpandCollapseListener() { @Override public void onExpand(View itemView, int position) { // Code } @Override public void onCollapse(View itemView, int position) { //Code } };

Are there solutions to fix the issue?

Thanks!

timonchev commented 9 years ago

also this issue....

chenchongyu commented 9 years ago

also this issue....

xsjqqq123 commented 8 years ago

also this issue....

hadidez commented 8 years ago

also this issue....