开发者

Why doesn't my preferences page show the current values?

开发者 https://www.devze.com 2023-01-16 16:35 出处:网络
I have a preferences page which is defined by XML - including some default values. I use a PreferenceActivity to display and handle this page. Whenever I use this page to set the preferences the prefe

I have a preferences page which is defined by XML - including some default values. I use a PreferenceActivity to display and handle this page. Whenever I use this page to set the preferences the preference file on the file system is updated properly - I can see this via adb.

However, whenever I go back to the settings page after have changed some of the settings, it's the defaults that are shown. Worse than that, if I press back without changing any settings, it then sets the, all back to the default.

Any ideas on how I can get the prefs to actually show the current settings?

My PreferenceActivityis created thus:

@Override
protected void onCreate(Bundle savedInstanceState) {
    PreferenceManager.getDefaultSharedPreferences(this)
            .registerOnSharedPreferenceChangeListener(this);
    setDefaults(this);
    super.onCreate(savedInstanceState);
    addPreferencesFromResource(R.xml.settings);
}

The XML looks like this:

    <?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen
  xmlns:android="http://schemas.android.com/apk/res/android">
  <ListPreference 
    android:id="@+id/numberOfYearsList"
    android:key="numberOfYears"
    android:title="Number of Years to Read the Bible"
    android:summary="How many years would you like to take to read through the reading plan?"
    android:entries="@array/numberOfYears"
    android:entryValues="@array/numberOfYears"
    android:dialogTitle="How Many Yea开发者_StackOverflow社区rs?"
    android:defaultValue="1"
    />
  <CheckBoxPreference android:key="ignoreDates"
    android:id="@+id/ignoreDatesCheckbox"
    android:title="Ignore Dates"
    android:summary="Would you like to use the dates in the plan?"
    android:defaultValue="false"
  />
</PreferenceScreen>


Nevermind - I did a mistake. As you can see from above, when creating the Preference Activity I'm making a call to a method that sets all the prefs to defaults... Duh!

0

精彩评论

暂无评论...
验证码 换一张
取 消