Is possible to change the summary of EditTextPreference dynamically in Android?

梦想与她 提交于 2019-12-05 13:33:19

Sure, here is a short example:

EditTextPreference etp = (EditTextPreference) findPreference("the_pref_key");
etp.setSummary("New summary");

This requires that you display your preferences either from a PreferenceActivity or from a PreferenceFragment, since findPreference() is a method of these classes. You most likely do that already.

To change the summary every time the user changes the actual preference, use a OnPreferenceChangeListener and check if the relevant key changed in the callback. After it has changed, just edit the summary like above.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!