Manipulating Preferences Programmatically
It goes without saying that you might need to access the actual preference controls programmatically. For example, what if you need to provide the
entryValues for the
ListPreference at runtime? You can define and access preference controls similarly to the way you define and access controls in layout files and activities. For example, to access the list preference defined in Listing 13–1, you would call the
findPreference() method of
PreferenceActivity, passing the preference's
key (note the similarity to
findViewById()). You would next cast the control to
ListPreference and then go about manipulating the control. For example, if you want to set the entries of the
ListPreference view, call ...
Get Pro Android 4 now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.