【发布时间】:2011-08-04 12:54:51
【问题描述】:
我有从 xml 膨胀的 PreferemceActivity:
<PreferenceScreen
android:title="Appearence"
android:key="AppearencePref" >
......
<PreferenceCategory
android:title="Show Contact Photos">
<CheckBoxPreference
android:title="Show Contact Photos"
android:summary="@string/show_contact_photos_preference"
android:defaultValue="true"
android:key="ShowContactPhotosCheckBoxPref_Appendix" />
</PreferenceCategory>
........
</PreferenceScreen>
.......
<PreferenceScreen
android:title="Contact Options"
android:key="ContactOtionsPref">
<PreferenceCategory
android:title="Show Contact Photos">
<CheckBoxPreference
android:title="Show Contact Photos"
android:defaultValue="true"
android:key="ShowContactPhotosCheckBoxPref" />
</PreferenceCategory>
......
</PreferenceScreen>
其中一个首选项(复选框)更改其他复选框的状态:
if("ShowContactPhotosCheckBoxPref_Appendix".equals(key)){
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
boolean isChecked = prefs.getBoolean("ShowContactPhotosCheckBoxPref_Appendix", false);
Editor editor = PreferenceManager.getDefaultSharedPreferences(mContext).edit();
editor.putBoolean("ShowContactPhotosCheckBoxPref", isChecked);
editor.commit();
}
但是当我使用 ShowContactPhotosCheckBoxPref 进入屏幕时,它仍然保留以前的首选项值... 因此,如果我单击 ShowContactPhotosCheckBoxPref_Appendix - 他的状态现在未选中,然后使用 ShowContactPhotosCheckBoxPref 进入屏幕 - 他的状态仍处于选中状态,但 SharedPreferences 中的值为 false...
如何告诉 PreferenceActivity 刷新它的值?
【问题讨论】:
标签: android preferenceactivity