您好,我需要知道如何以编程方式设置值。
我正在使用该代码
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
.
.
.
SharedPreferences.Editor geted = prefs.edit();
geted.putBoolean("checkBox_Schedule", false);
geted.commit();
但我没有看到任何变化
我的 checkboxPreference 的 xml 代码是
<CheckBoxPreference
android:defaultValue="false"
android:dependency="checkBox"
android:key="checkBox_Schedule"
android:summary="On/Off"
android:title="Schedule" />
一个解决方案是做
startActivity(new Intent(SetPreference.this, SetPreference.class));
但这不是我想做的。
最佳答案
CheckBoxPreference showContact = (CheckBoxPreference)findPreference("myPreference");
showContact.setChecked(false);
关于android - 在 Activity 中设置 CheckBoxPreference 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12423748/