2

Maybe the question is very trivial and my google-skills are not good enough but I couldn't find any solution for the following Problem.

I've built a PreferenceFragment which is compatible with the android-support-library by using this workaround. It works fine and was very simple to implement.

When opening this Fragment (in the onCreate()) the current value of each Preference will be shown in the summary of the preference object by using:

preference.setSummary(stringValue);

It works well for all EditTextPreference, ListPreference and - with a simple addition - for CheckboxPreference, too. But I have another Preference:

<Preference 
    android:key="minInputLength"
    android:defaultValue="@integer/numberPickerInputLengthDefaultValue"
    android:title="@string/minInputLength"/>

When the cache of the App is empty and the onCreate method is called, the summary of this and only this preference is empty, although I've called this method:

PreferenceManager.setDefaultValues(this, R.layout.fragment_settings, true);

in the Main activity. Otherwise the summaries of all the other Preferences would be empty too.

The Preference above just opens a Dialog, which contains a simple NumberPicker in its content area. If I change the value within the NumberPicker and exit the dialog by pressing the PositiveButton of the dialog, the summary of this Preference changes like expected. If I clear the cache and open the fragment again the summary is empty again.

So I tried to figure out why and displayed all SharedPreferences via LogCat and recognized that this and only this preference is missing. This is the reason why I ask myself: does the PreferenceManager ignore the defaultValue, which is declared in the xml, of <preference />?

EDIT: Or is this problem caused by the workaround I mentioned?

These two Links summarize my research, but there was no solution for my Problem (or I am just too blind to see):

Community
  • 1
  • 1
jtight_404
  • 51
  • 5

0 Answers0