setChecked的开关无法正常工作

时间:2016-02-20 16:22:38

标签: android uiswitch

我在我的应用中使用了一个开关来启用和禁用通知。现在我正在创建一个活动。

如果有任何通知设置为该事件,我想显示开关,否则它应该为false。但我没有得到任何改变。每次都会显示开关。

当我进行调试时,如果通知不为空,那么它将转到其他部分,但切换剂量不显示。

 notificationTime = eventData.getNotificationTime();

        if(notificationTime.equals(""))
        {
            notify.setChecked(false);
        }
        else {
            notify.setChecked(true);
        }

出了什么问题?

1 个答案:

答案 0 :(得分:0)

这是在Android中处理交换机的正确方法。

    mySwitch.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
    public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
        // do something, the isChecked will be
        // true if the switch is in the On position
    }
});
相关问题