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

前端 未结 14 1111
感动是毒
感动是毒 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 04:00

    Simplest way in Kotlin

    findPreference(getString(R.string.pref_some_key)).apply {
        summary = entry
        setOnPreferenceChangeListener { _, newValue ->
            summary = entries[entryValues.indexOf(newValue)]
            return@setOnPreferenceChangeListener true
        }
    }
    

提交回复
热议问题