gpt4 book ai didi

android - PreferenceActivity刷新问题

转载 作者:太空狗 更新时间:2023-10-29 14:32:06 25 4
gpt4 key购买 nike

我有从 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 刷新它的值?

最佳答案

解决方案在 ApiDemos AdvancedPreferences.java 中:

private CheckBoxPreference mCheckBoxPreference;

mCheckBoxPreference = (CheckBoxPreference)getPreferenceScreen().findPreference(
KEY_ADVANCED_CHECKBOX_PREFERENCE);

if (mCheckBoxPreference != null) {
mCheckBoxPreference.setChecked(!mCheckBoxPreference.isChecked());
}

关于android - PreferenceActivity刷新问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5646683/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com