androidkotlinsharedpreferencespreferencefragmentedittextpreference

Android Preference. How to force update summary for the preference with SummaryProvider setted?


I have a modified EditTextPreference with using SimpleSummaryProvider:

<NumberPreference
    android:key="pref_key"
    android:defaultValue="0"
    android:title="Some title"
    app:useSimpleSummaryProvider="true"/>

If I change this preference programmatically (for example in the onSharedPreferenceChanged event), then the summary in the graphical interface will not update. Is there any way to notify the Preference widget that it needs to read the value again and display it in the summary? Without manually assigning a specific value to the summary?

I am using PreferenceFragmentCompat and a modified EditTextPreference with a modified EditTextPreferenceDialogFragmentCompat.


Solution

  • I looked at the Android sources (EditTextPreferenceDialogFragmentCompat.java) - how the dialog for changing settings notifies EditTextPreference about a value change. Did as well and it worked :)

    if (editTextPreference().callChangeListener(value)) {
        editTextPreference().setText(value);
    }