Deepzz
Deepzz

Reputation: 4571

How to add Preference in ICS

I need to add Preference in ICS using addPreferencesFromResource().
It is shown as deprecated in ICS.
I've added a preference layout in xml folder but this could not be added to the Preference activity.

How can I add it?

Upvotes: 4

Views: 352

Answers (1)

CommonsWare
CommonsWare

Reputation: 1007296

On API Level 11 and higher, the plan is for you to use PreferenceFragments to call addPreferencesFromResource(). You can see an example of this in the documentation for PreferenceActivity.

If you are trying to support PreferenceFragment on API Level 11+, yet still support older devices, you will need to do both the stuff shown in that documentation and call addPreferencesFromResource() directly in your PreferenceActivity... but only when you are on an older device. Even though addPreferencesFromResource() is marked as deprecated, that does not mean that it does not work, and more importantly it is your only option on API Level 10 and below.

Here is a sample project where I demonstrate supporting both API Level 11-style fragments and the classic PreferenceActivity from a single set of source.

Upvotes: 2

Related Questions