Code example for Switch

Methods: isChecked, setChecked

0
                setSwitchChecked(false); 
                mSwitch.setEnabled(true);
                break; 
        } 
    } 
 
    private void setSwitchChecked(boolean checked) {
        if (checked != mSwitch.isChecked()) {
            mStateMachineEvent = true;
            mSwitch.setChecked(checked);
            mStateMachineEvent = false;
        } 
    } 
 
    private void handleStateChanged(@SuppressWarnings("unused") NetworkInfo.DetailedState state) {
        // After the refactoring from a CheckBoxPreference to a Switch, this method is useless since 
        // there is nowhere to display a summary. 
        // This code is kept in case a future change re-introduces an associated text. 
        /* 
        // WifiInfo is valid if and only if Wi-Fi is enabled. 
        // Here we use the state of the switch as an optimization.