SwitchPreference未关闭

时间:2016-10-16 03:38:59

标签: java android sharedpreferences

我想在满足条件时关闭开关首选项,我已编写代码但仍然没有将其关闭。怎么解决?

其中p1是字符串,从path();返回。我能够显示Toast,但是.ischecked(false)无效。

 enableapp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                if (!enableapp.isChecked()) {
                    path();
                    if (p1.isEmpty()) {
                        Toast.makeText(FinalSettings.this, "Your Device Does not Support", Toast.LENGTH_LONG).show();
                        enableapp.setChecked(false);

                    }

1 个答案:

答案 0 :(得分:0)

试试这个

enableapp.setOnPreferenceChangeListener(new Preference.OnPreferenceChangeListener() {
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) {
            if (!enableapp.isChecked()) {
                if (path().isEmpty()) {
                    Toast.makeText(FinalSettings.this, "Your Device Does not Support", Toast.LENGTH_LONG).show();
                    enableapp.setChecked(false);

                }

p1 - 非初始化,因此不满足条件。