public abstract class PreferenceGroup extends Preference implements GenericInflater.Parent<Preference>
Preference
objects. It is a base class for Preference objects that are
parents, such as PreferenceCategory
and PreferenceScreen
.
For information about building a settings UI with Preferences, read the Settings guide.
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
PreferenceGroup(Context context,
AttributeSet attrs) |
PreferenceGroup(Context context,
AttributeSet attrs,
int defStyle) |
Modifier and Type | Method and Description |
---|---|
void |
addItemFromInflater(Preference preference)
Called by the inflater to add an item to this group.
|
boolean |
addPreference(Preference preference)
Adds a
Preference at the correct position based on the
preference's order. |
protected void |
dispatchRestoreInstanceState(Bundle container)
Called by
Preference.restoreHierarchyState(android.os.Bundle) to retrieve the saved state for this
Preference and its children. |
protected void |
dispatchSaveInstanceState(Bundle container)
Called by
Preference.saveHierarchyState(android.os.Bundle) to store the instance for this Preference and its children. |
Preference |
findPreference(CharSequence key)
Finds a
Preference based on its key. |
Preference |
getPreference(int index)
Returns the
Preference at a particular index. |
int |
getPreferenceCount()
Returns the number of children
Preference s. |
protected boolean |
isOnSameScreenAsChildren()
Whether this preference group should be shown on the same screen as its
contained preferences.
|
boolean |
isOrderingAsAdded()
Whether this group is ordering preferences in the order they are added.
|
protected void |
onAttachedToActivity()
Called when the Preference hierarchy has been attached to the
PreferenceActivity . |
protected boolean |
onPrepareAddPreference(Preference preference)
Prepares a
Preference to be added to the group. |
protected void |
onPrepareForRemoval()
Called when this Preference is being removed from the hierarchy.
|
void |
removeAll()
Removes all
Preferences from this group. |
boolean |
removePreference(Preference preference)
Removes a
Preference from this group. |
void |
setEnabled(boolean enabled)
Sets whether this Preference is enabled.
|
void |
setOrderingAsAdded(boolean orderingAsAdded)
Whether to order the
Preference children of this group as they
are added. |
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, onClick, onCreateView, onDependencyChanged, onGetDefaultValue, onKey, onRestoreInstanceState, onSaveInstanceState, 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 PreferenceGroup(Context context, AttributeSet attrs, int defStyle)
public PreferenceGroup(Context context, AttributeSet attrs)
public void setOrderingAsAdded(boolean orderingAsAdded)
Preference
children of this group as they
are added. If this is false, the ordering will follow each Preference
order and default to alphabetic for those without an order.
If this is called after preferences are added, they will not be re-ordered in the order they were added, hence call this method early on.
orderingAsAdded
- Whether to order according to the order added.Preference.setOrder(int)
public boolean isOrderingAsAdded()
setOrderingAsAdded(boolean)
public void addItemFromInflater(Preference preference)
addItemFromInflater
in interface GenericInflater.Parent<Preference>
public int getPreferenceCount()
Preference
s.public Preference getPreference(int index)
Preference
at a particular index.index
- The index of the Preference
to retrieve.Preference
.public boolean addPreference(Preference preference)
Preference
at the correct position based on the
preference's order.preference
- The preference to add.public boolean removePreference(Preference preference)
Preference
from this group.preference
- The preference to remove.public void removeAll()
Preferences
from this group.protected boolean onPrepareAddPreference(Preference preference)
Preference
to be added to the group.preference
- The preference to add.public Preference findPreference(CharSequence key)
Preference
based on its key. If two Preference
share the same key (not recommended), the first to appear will be
returned (to retrieve the other preference with the same key, call this
method on the first preference). If this preference has the key, it will
not be returned.
This will recursively search for the preference into children that are
also PreferenceGroups
.
key
- The key of the preference to retrieve.Preference
with the key, or null.protected boolean isOnSameScreenAsChildren()
protected void onAttachedToActivity()
Preference
PreferenceActivity
. This can also be called when this
Preference has been attached to a group that was already attached
to the PreferenceActivity
.onAttachedToActivity
in class Preference
protected void onPrepareForRemoval()
Preference
onPrepareForRemoval
in class Preference
public void setEnabled(boolean enabled)
Preference
setEnabled
in class Preference
enabled
- Set true to enable it.protected void dispatchSaveInstanceState(Bundle container)
Preference
Preference.saveHierarchyState(android.os.Bundle)
to store the instance for this Preference and its children.
May be overridden to modify how the save happens for children. For example, some
Preference objects may want to not store an instance for their children.container
- The Bundle in which to save the instance of this Preference.Preference.saveHierarchyState(android.os.Bundle)
,
Preference.onSaveInstanceState()
protected void dispatchRestoreInstanceState(Bundle container)
Preference
Preference.restoreHierarchyState(android.os.Bundle)
to retrieve the saved state for this
Preference and its children. May be overridden to modify how restoring
happens to the children of a Preference. For example, some Preference objects may
not want to save state for their children.container
- The Bundle that holds the previously saved state.Preference.restoreHierarchyState(android.os.Bundle)
,
Preference.onRestoreInstanceState(android.os.Parcelable)