androidandroid-switch

Switch Set Checked False


I've a Switch with a listener:

mSwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton compoundButton, boolean checked) {
}

Doing:

mSwitch.setChecked(false);

has no effect, callback is not triggered. Instead like this:

mSwitch.setChecked(true);
mSwitch.setChecked(false);

works as expected. Am I doing something wrong? If the checkbox state is false and one use setChecked(false), the normal behaviour is to skip callback? Or is it a bug?


Solution

  • It will be Called when the checked state of a compound button has changed.

    So if its state is already false it won't be called when you call false.