public abstract class PreferenceGroup
extends Preference

   ↳ androidx.preference.Preference
     ↳ androidx.preference.PreferenceGroup

A container for multiple Preferences. It is a base class for preference objects that are parents, such as PreferenceCategory and PreferenceScreen.

Developer Guides

For information about building a settings screen using the AndroidX Preference library, see Settings.


Nested classes

interface PreferenceGroup.PreferencePositionCallback

Interface for PreferenceGroup adapters to implement so that PreferenceFragmentCompat.scrollToPreference(String) and PreferenceFragmentCompat.scrollToPreference(Preference) can determine the correct scroll position to request. 

Inherited constants

Public constructors

PreferenceGroup(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes)
PreferenceGroup(Context context, AttributeSet attrs, int defStyleAttr)
PreferenceGroup(Context context, AttributeSet attrs)

Public methods

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.

<T extends Preference> T findPreference(CharSequence key)

Finds a Preference based on its key.

int getInitialExpandedChildrenCount()

Gets the maximal number of children that are initially shown.

Preference getPreference(int index)

Returns the Preference at a particular index.

int getPreferenceCount()

Returns the number of children Preferences.

boolean isOrderingAsAdded()

Whether this group is ordering preferences in the order they are added.

void notifyDependencyChange(boolean disableDependents)

Notifies any listening dependents of a change that affects the dependency.

void onAttached()

Called when the preference hierarchy has been attached to the list of preferences.

void onDetached()

Called when the preference hierarchy has been detached from the list of preferences.

void removeAll()

Removes all Preferences from this group.

boolean removePreference(Preference preference)

Removes a Preference from this group.

boolean removePreferenceRecursively(CharSequence key)

Recursively finds and removes a Preference from this group or a nested group lower down in the hierarchy.

void setInitialExpandedChildrenCount(int expandedCount)

Sets the maximal number of children that are shown when the preference group is launched where the rest of the children will be hidden.

void setOrderingAsAdded(boolean orderingAsAdded)

Whether to order the Preference children of this group as they are added.

Protected methods

void dispatchRestoreInstanceState(Bundle container)

Called by restoreHierarchyState(Bundle) to retrieve the saved state for this preference and its children.

void dispatchSaveInstanceState(Bundle container)

Called by saveHierarchyState(Bundle) to store the instance for this preference and its children.

boolean isOnSameScreenAsChildren()

Whether this preference group should be shown on the same screen as its contained preferences.

boolean onPrepareAddPreference(Preference preference)

Prepares a Preference to be added to the group.

void onRestoreInstanceState(Parcelable state)

Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState().