E
E
Eugene2020-01-30 20:57:11
Android
Eugene, 2020-01-30 20:57:11

What is the best way to update the summary of a modified EditTextPreference with the SimpleSummaryProvider set?

I have a modified EditTextPreference (with a modified EditTextPreferenceDialogFragmentCompat ) that uses the SimpleSummaryProvider :

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

If I change the corresponding setting (in this case "pref_key" ) programmatically (let's say when changing another setting), then the value in the graphical view is not automatically updated (the value itself changes, the onSharedPreferenceChanged event is processed for the programmatically changed setting). The documentation seems to say that if you use the setSummary method with the SummaryProvider already set , then there will be an error. And I would not want to manually update the value. Is there any way to force the corresponding Preference to re-query the value and update the graphical representation?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-01-31
@phoenixbk

I looked at the Android sources ( EditTextPreferenceDialogFragmentCompat.java ) - how the settings change dialog notifies the EditTextPreference about a value change. I did the same and it worked :)

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

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question