• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps PreferenceActivity Refresh Problem

vovs

Newbie
Hi, guys!

I have PreferemceActivity inflated from xml:

Code:
<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>
One of the preferences(checkbox) change state of other checkbox:

Code:
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();            
        }
But when I go to screen with ShowContactPhotosCheckBoxPref it still hold previous preference value...

How can I tell PreferenceActivity to refresh its value?
 
It is very simple:

Code:
if("ShowContactPhotosCheckBoxPref_Appendix".equals(key)){
    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(mContext);
    boolean isChecked =    prefs.getBoolean("ShowContactPhotosCheckBoxPref_Appendix", false);
    if (isChecked != prefs.getBoolean("ShowContactPhotosCheckBoxPref", false)){
        CheckBoxPreference showContact = (CheckBoxPreference)findPreference("ShowContactPhotosCheckBoxPref");
        showContact.setChecked(isChecked);
    }						
}

hope, this helps to someone
 
Back
Top Bottom