I'm looking for a method of programmatically changing the state of an Android Switch widget using switch.setChecked(true);
without triggering OnCheckedChangedlistener
.
My first thought was to swap it out for an OnClickListener
but as this only registers clicks and you are able to not only click but also slide a Switch then it's not really fit for purpose as if the user was to slide the Switch from off to on then the Switch would actually do nothing as the user is not clicking...
If anyone's got a solution or a smart work around for this, that would be awesome
Set the listener to null before calling setCheck() function, and enable it after that, such as the following:
switch.setOnCheckedChangeListener (null); switch.setChecked(true); switch.setOnCheckedChangeListener (this);
Reference: Change Checkbox value without triggering onCheckChanged
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