O'Reilly logo

Pro Android 4 by Satya Komatineni, Dave MacLean

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required