public final class PreferenceScreen extends PreferenceGroup
Preference
that
is the root of a Preference hierarchy. A PreferenceFragmentCompat
points to an instance of this class to show the preferences. To instantiate
this class, use PreferenceManager.createPreferenceScreen(android.content.Context)
.
PreferenceFragmentCompat
points to this, it is used as the root
and is not shown (only the contained preferences are shown).
Dialog
or via a
Context.startActivity(android.content.Intent)
from the
Preference.getIntent()
). The children of this PreferenceScreen
are NOT shown in the screen that this PreferenceScreen
is shown in.
Instead, a separate screen will be shown when this preference is clicked.
Here's an example XML layout of a PreferenceScreen:
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android" android:key="first_preferencescreen"> <CheckBoxPreference android:key="wifi enabled" android:title="WiFi" /> <PreferenceScreen android:key="second_preferencescreen" android:title="WiFi settings"> <CheckBoxPreference android:key="prefer wifi" android:title="Prefer WiFi" /> ... other preferences here ... </PreferenceScreen> </PreferenceScreen>
In this example, the "first_preferencescreen" will be used as the root of the
hierarchy and given to a PreferenceFragment
or PreferenceFragmentCompat
.
The first screen will
show preferences "WiFi" (which can be used to quickly enable/disable WiFi)
and "WiFi settings". The "WiFi settings" is the "second_preferencescreen" and when
clicked will show another screen of preferences such as "Prefer WiFi" (and
the other preferences that are children of the "second_preferencescreen" tag).
For information about building a settings UI with Preferences, read the Settings guide.
PreferenceCategory
PreferenceGroup.PreferencePositionCallback
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
PreferenceScreen(Context context,
AttributeSet attrs)
Do NOT use this constructor, use
PreferenceManager.createPreferenceScreen(Context) . |
Modifier and Type | Method and Description |
---|---|
protected boolean |
isOnSameScreenAsChildren()
Whether this preference group should be shown on the same screen as its
contained preferences.
|
protected void |
onClick()
Processes a click on the preference.
|
void |
setShouldUseGeneratedIds(boolean shouldUseGeneratedIds)
Set whether the adapter created for this screen should attempt to use the preference IDs
generated by
PreferenceGroup.addPreference(Preference) as stable item IDs. |
boolean |
shouldUseGeneratedIds()
|
addItemFromInflater, addPreference, dispatchRestoreInstanceState, dispatchSaveInstanceState, findPreference, getPreference, getPreferenceCount, isAttached, isOrderingAsAdded, notifyDependencyChange, onAttached, onDetached, onPrepareAddPreference, removeAll, removePreference, setOrderingAsAdded
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, isVisible, notifyChanged, notifyHierarchyChanged, onAttachedToHierarchy, onAttachedToHierarchy, onBindViewHolder, onDependencyChanged, onGetDefaultValue, onInitializeAccessibilityNodeInfo, onParentChanged, onPrepareForRemoval, onRestoreInstanceState, onSaveInstanceState, onSetInitialValue, peekExtras, performClick, performClick, persistBoolean, persistFloat, persistInt, persistLong, persistString, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setViewId, setVisible, setWidgetLayoutResource, shouldDisableDependents, shouldPersist, toString
public PreferenceScreen(Context context, AttributeSet attrs)
PreferenceManager.createPreferenceScreen(Context)
.protected void onClick()
Preference
SharedPreferences
. However, the overridden method should
call Preference.callChangeListener(Object)
to make sure the client wants to
update the preference's state with the new value.onClick
in class Preference
protected boolean isOnSameScreenAsChildren()
PreferenceGroup
isOnSameScreenAsChildren
in class PreferenceGroup
public boolean shouldUseGeneratedIds()
true
if the adapter should use the preference IDs generated by
PreferenceGroup.addPreference(Preference)
as stable item IDspublic void setShouldUseGeneratedIds(boolean shouldUseGeneratedIds)
PreferenceGroup.addPreference(Preference)
as stable item IDs. Setting
this to false can suppress unwanted animations if Preference
objects are frequently
removed from and re-added to their containing PreferenceGroup
.
This method may only be called when the preference screen is not attached to the hierarchy.
Default value is true
.
shouldUseGeneratedIds
- true
if the adapter should use the preference ID as a
stable ID, or false
to disable the use of
stable IDs