Switch Set Checked False

Jumpa picture Jumpa · Jun 8, 2016 · Viewed 9.1k times · Source

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?

Answer

Nongthonbam Tonthoi picture Nongthonbam Tonthoi · Jun 8, 2016

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.