Reputation: 35
i want to set a preference summary , usually it can be done with
EditTextPreference Pref = (EditTextPreference) findPreference(key);
Pref.setSummary("new summary");
but since Android 4.1, findPreference throws an NPE (?), is there any other method to set the summary of a preference in preferenceHeaders/preferenceFragment ? (but not with xml, i need the summary value to be dynamic)
Upvotes: 1
Views: 7584
Reputation: 134714
Your problem is elsewhere. findPreference()
may be deprecated, but it is still available for use in the API -- it just isn't relevant if you're using Fragments.
See the Android 4.2 source for PreferenceActivity
that shows the method clearly still available.
I use it for all preferences in my application, and have no issues even on 4.2.2.
If you're using PreferenceFragments
, be aware that you should use the findPreference()
method on your PreferenceFragment
instance rather than from a PreferenceActivity
.
See this documentation for more information.
Upvotes: 5