Search code examples
androidandroid-4.0-ice-cream-sandwichpreferences

Can't add Preference in ICS


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


Solution

  • From HC/ICS onward you should use PreferenceFragment.addPreferencesFromResource() instead of Activity.addPreferencesFromResource(). However, this does require you switch how your preference code is structured - moving from an old style PreferenceActivity which directly adds the preferences to a new style PreferenceActivity that loads PreferenceFragments that then load the preferences. For an example of the new way, see the code sample in the PreferenceActivity docs.

    Note that the support library does not PreferenceFragment for backward compatibility pre-HC.