Change the summary of a ListPreference with the new value (Android)

前端 未结 14 1142
感动是毒
感动是毒 2020-12-30 03:01

How can I modify the summary of a ListPreference to the new \"Entry\" string selected by the user (not the entry value)

I suppouse its with setOnPreferenceChangeList

14条回答
  •  不思量自难忘°
    2020-12-30 03:43

    There is no need to extend ListPreference or to loop over the entryValues etc

    public boolean onPreferenceChange(Preference preference, Object newValue) {
        int i = ((ListPreference)preference).findIndexOfValue(newValue.toString());
        CharSequence[] entries = ((ListPreference)preference).getEntries();
        preference.setSummary(entries[i]);
    
        return true;
    }
    

提交回复
热议问题