public final class PreferenceScreen extends PreferenceGroup implements AdapterView.OnItemClickListener, DialogInterface.OnDismissListener
Preference
that
is the root of a Preference hierarchy. A PreferenceActivity
points to an instance of this class to show the preferences. To instantiate
this class, use PreferenceManager.createPreferenceScreen(Context)
.
PreferenceActivity
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 PreferenceActivity
. 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
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 |
---|---|
void |
bind(ListView listView)
|
Dialog |
getDialog()
Used to get a handle to the dialog.
|
ListAdapter |
getRootAdapter()
Returns an adapter that can be attached to a
PreferenceActivity
or PreferenceFragment to show the preferences contained in this
PreferenceScreen . |
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.
|
protected ListAdapter |
onCreateRootAdapter()
Creates the root adapter.
|
void |
onDismiss(DialogInterface dialog)
This method will be invoked when the dialog is dismissed.
|
void |
onItemClick(AdapterView parent,
View view,
int position,
long id)
Callback method to be invoked when an item in this AdapterView has
been clicked.
|
protected void |
onRestoreInstanceState(Parcelable state)
Hook allowing a Preference to re-apply a representation of its internal
state that had previously been generated by
Preference.onSaveInstanceState() . |
protected Parcelable |
onSaveInstanceState()
Hook allowing a Preference to generate a representation of its internal
state that can later be used to create a new instance with that same
state.
|
addItemFromInflater, addPreference, dispatchRestoreInstanceState, dispatchSaveInstanceState, findPreference, getPreference, getPreferenceCount, isOrderingAsAdded, onAttachedToActivity, onPrepareAddPreference, onPrepareForRemoval, removeAll, removePreference, setEnabled, setOrderingAsAdded
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getEditor, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPersistedStringSet, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getTitleRes, getView, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToHierarchy, onBindView, onCreateView, onDependencyChanged, onGetDefaultValue, onKey, onSetInitialValue, peekExtras, persistBoolean, persistFloat, persistInt, persistLong, persistString, persistStringSet, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldDisableDependents, shouldPersist, toString
public PreferenceScreen(Context context, AttributeSet attrs)
PreferenceManager.createPreferenceScreen(Context)
.public ListAdapter getRootAdapter()
PreferenceActivity
or PreferenceFragment
to show the preferences contained in this
PreferenceScreen
.
This PreferenceScreen
will NOT appear in the returned adapter, instead
it appears in the hierarchy above this PreferenceScreen
.
This adapter's Adapter.getItem(int)
should always return a
subclass of Preference
.
Preference
contained in this
PreferenceScreen
.protected ListAdapter onCreateRootAdapter()
PreferenceScreen
.getRootAdapter()
public void bind(ListView listView)
ListView
to the preferences contained in this PreferenceScreen
via
getRootAdapter()
. It also handles passing list item clicks to the corresponding
Preference
contained by this PreferenceScreen
.listView
- The list view to attach to.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
public void onDismiss(DialogInterface dialog)
DialogInterface.OnDismissListener
onDismiss
in interface DialogInterface.OnDismissListener
dialog
- The dialog that was dismissed will be passed into the
method.public Dialog getDialog()
public void onItemClick(AdapterView parent, View view, int position, long id)
AdapterView.OnItemClickListener
Implementers can call getItemAtPosition(position) if they need to access the data associated with the selected item.
onItemClick
in interface AdapterView.OnItemClickListener
parent
- The AdapterView where the click happened.view
- The view within the AdapterView that was clicked (this
will be a view provided by the adapter)position
- The position of the view in the adapter.id
- The row id of the item that was clicked.protected boolean isOnSameScreenAsChildren()
PreferenceGroup
isOnSameScreenAsChildren
in class PreferenceGroup
protected Parcelable onSaveInstanceState()
Preference
onSaveInstanceState
in class Preference
Preference.onRestoreInstanceState(android.os.Parcelable)
,
Preference.saveHierarchyState(android.os.Bundle)
protected void onRestoreInstanceState(Parcelable state)
Preference
Preference.onSaveInstanceState()
.
This function will never be called with a null state.onRestoreInstanceState
in class Preference
state
- The saved state that had previously been returned by
Preference.onSaveInstanceState()
.Preference.onSaveInstanceState()
,
Preference.restoreHierarchyState(android.os.Bundle)