Is there any way to remove a Listener from a View
in android? I have a Checkbox
that I attached a CheckChangedListener
to. The problem is that calling setChecked()
on it causes my listener to fire.
If I can't just remove a listener, is there a way to prevent the listener from firing when I call setChecked()
manually versus it being checked from a touch event?
Well, I found the answer. This doesnt appear to be documented anywhere, but I went through the code for the View
class and if you pass null to the setClickListener methods, it will remove the listener.
checkbox.setOnCheckChangedListener(null);
This should work for any event listener.
Why have you got a checkChangeListener
? If you'd use an onClicklListener
it might just work for you?
You could try setting the listener to one that does nothing before calling setChecked()
and then putting the useful one back afterwards.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With