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 entries and 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 O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.