有可能改变的EditText $ P $ Android中动态pference的总结? [英] Is possible to change the summary of EditTextPreference dynamically in Android?
问题描述
我设置了一个preferenceScreen在我的应用程序来编辑这些设置。我想插入包含像标题一个EditText preference设置你的名字,并包含输入名称的摘要。
I set up a preferenceScreen to edit the settings in my application. I would like to insert an EditTextPreference that contains a Title like "set your name" and a summary containing the name entered.
这可能吗?预先感谢您!
Is that possible? thank you in advance!
推荐答案
当然,这里是一个简单的例子:
Sure, here is a short example:
EditTextPreference etp = (EditTextPreference) findPreference("the_pref_key");
etp.setSummary("New summary");
这需要你显示你的preferences无论是从 preferenceActivity
或从 preferenceFragment
,因为找到preference()
是这些类的方法。你最有可能做到这一点了。
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.
要在每次用户改变实际preference时间变化的总结,使用<一个href=\"http://developer.android.com/reference/android/$p$pference/$p$pference.On$p$pferenceChangeListener.html\"><$c$c>On$p$pferenceChangeListener$c$c>并检查相应的键回调改变。
它已经改变之后,只需编辑类似于上面的总结。
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.
这篇关于有可能改变的EditText $ P $ Android中动态pference的总结?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!