PreferenceFragment
Deprecated
Use PreferenceFragmentCompat instead
(SESL variant) Shows a hierarchy of Preference objects as lists. These preferences will automatically save to android.content.SharedPreferences as the user interacts with them. To retrieve an instance of android.content.SharedPreferences that the preference hierarchy in this fragment will use, call getDefaultSharedPreferences with a context in the same package as this fragment.
Furthermore, the preferences shown will follow the visual style of system preferences. It is easy to create a hierarchy of preferences (that can be shown on multiple screens) via XML. For these reasons, it is recommended to use this fragment (as a superclass) to deal with preferences in applications.
A PreferenceScreen object should be at the top of the preference hierarchy. Furthermore, subsequent PreferenceScreen in the hierarchy denote a screen break--that is the preferences contained within subsequent PreferenceScreen should be shown on another screen. The preference framework handles this by calling onNavigateToScreen.
The preference hierarchy can be formed in multiple ways:
- From an XML file specifying the hierarchy
- From different Activities that each specify its own preferences in an XML file via android.app.Activity meta-data
- From an object hierarchy rooted with PreferenceScreen
To inflate from XML, use the addPreferencesFromResource. The root element should be a PreferenceScreen. Subsequent elements can point to actual Preference subclasses. As mentioned above, subsequent PreferenceScreen in the hierarchy will result in the screen break.
To specify an object hierarchy rooted with PreferenceScreen, use setPreferenceScreen.
As a convenience, this fragment implements a click listener for any preference in the current hierarchy, see onPreferenceTreeClick.
See also
Types
Properties
Functions
key
.