PreferenceGroup
public abstract class PreferenceGroup extends Preference
PreferenceCategory |
A container that is used to group similar |
PreferenceScreen |
A top-level container that represents a settings screen. |
A container for multiple Preferences. It is a base class for preference objects that are parents, such as PreferenceCategory and PreferenceScreen.
name android:orderingFromXml
name initialExpandedChildrenCount
Summary
Nested types |
|---|
public interface PreferenceGroup.PreferencePositionCallbackInterface for PreferenceGroup adapters to implement so that |
Public constructors |
|---|
PreferenceGroup(@NonNull Context context, @Nullable AttributeSet attrs) |
PreferenceGroup( |
PreferenceGroup( |
Public methods |
|
|---|---|
void |
addItemFromInflater(@NonNull Preference preference)Called by the inflater to add an item to this group. |
boolean |
addPreference(@NonNull Preference preference)Adds a |
@Nullable T |
<T extends Preference> findPreference(@NonNull CharSequence key)Finds a |
int |
Gets the maximal number of children that are initially shown. |
@NonNull Preference |
getPreference(int index)Returns the |
int |
Returns the number of children |
boolean |
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 |
Called when the preference hierarchy has been attached to the list of preferences. |
void |
Called when the preference hierarchy has been detached from the list of preferences. |
void |
Removes all |
boolean |
removePreference(@NonNull Preference preference)Removes a |
boolean |
Recursively finds and removes a |
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 |
Protected methods |
|
|---|---|
void |
dispatchRestoreInstanceState(@NonNull Bundle container)Called by |
void |
dispatchSaveInstanceState(@NonNull Bundle container)Called by |
boolean |
Whether this preference group should be shown on the same screen as its contained preferences. |
boolean |
onPrepareAddPreference(@NonNull Preference preference)Prepares a |
void |
onRestoreInstanceState(@Nullable Parcelable state)Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by |
@NonNull Parcelable |
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. |
Extension functions |
|
|---|---|
final boolean |
PreferenceGroupKt.contains(Returns |
final void |
PreferenceGroupKt.forEach(Performs the given action on each preference in this preference group. |
final void |
PreferenceGroupKt.forEachIndexed(Performs the given action on each preference in this preference group, providing its sequential index. |
final @NonNull Preference |
PreferenceGroupKt.get(@NonNull PreferenceGroup receiver, int index)Returns the preference at |
final T |
<T extends Preference> PreferenceGroupKt.get(Returns the preference with |
final @NonNull Sequence<@NonNull Preference> |
PreferenceGroupKt.getChildren(@NonNull PreferenceGroup receiver)Returns a |
final int |
PreferenceGroupKt.getSize(@NonNull PreferenceGroup receiver)Returns the number of preferences in this preference group. |
final boolean |
PreferenceGroupKt.isEmpty(@NonNull PreferenceGroup receiver)Returns true if this preference group contains no preferences. |
final boolean |
PreferenceGroupKt.isNotEmpty(@NonNull PreferenceGroup receiver)Returns true if this preference group contains one or more preferences. |
final @NonNull Iterator<@NonNull Preference> |
PreferenceGroupKt.iterator(@NonNull PreferenceGroup receiver)Returns a |
final void |
PreferenceGroupKt.minusAssign(Removes |
final void |
PreferenceGroupKt.plusAssign(Adds |
Inherited Constants |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
PreferenceGroup
public PreferenceGroup(@NonNull Context context, @Nullable AttributeSet attrs)
PreferenceGroup
public PreferenceGroup(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
PreferenceGroup
public PreferenceGroup(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
int defStyleRes
)
Public methods
addItemFromInflater
public void addItemFromInflater(@NonNull Preference preference)
Called by the inflater to add an item to this group.
addPreference
public boolean addPreference(@NonNull Preference preference)
Adds a Preference at the correct position based on the preference's order.
| Parameters | |
|---|---|
@NonNull Preference preference |
The preference to add |
| Returns | |
|---|---|
boolean |
Whether the preference is now in this group |
findPreference
public @Nullable T <T extends Preference> findPreference(@NonNull CharSequence key)
Finds a Preference based on its key. If two Preferences share the same key (not recommended), the first to appear will be returned.
This will recursively search for the Preference in any children that are also PreferenceGroups.
| Parameters | |
|---|---|
@NonNull CharSequence key |
The key of the |
| Returns | |
|---|---|
@Nullable T |
The |
getInitialExpandedChildrenCount
public int getInitialExpandedChildrenCount()
Gets the maximal number of children that are initially shown.
| Returns | |
|---|---|
int |
The maximal number of children that are initially shown initialExpandedChildrenCount |
getPreference
public @NonNull Preference getPreference(int index)
Returns the Preference at a particular index.
| Parameters | |
|---|---|
int index |
The index of the |
| Returns | |
|---|---|
@NonNull Preference |
The |
getPreferenceCount
public int getPreferenceCount()
Returns the number of children Preferences.
| Returns | |
|---|---|
int |
The number of preference children in this group |
isOrderingAsAdded
public boolean isOrderingAsAdded()
Whether this group is ordering preferences in the order they are added.
| Returns | |
|---|---|
boolean |
Whether this group orders based on the order the children are added |
| See also | |
|---|---|
setOrderingAsAdded |
notifyDependencyChange
public void notifyDependencyChange(boolean disableDependents)
Notifies any listening dependents of a change that affects the dependency.
| Parameters | |
|---|---|
boolean disableDependents |
Whether this preference should disable its dependents. |
onAttached
public void onAttached()
Called when the preference hierarchy has been attached to the list of preferences. This can also be called when this preference has been attached to a group that was already attached to the list of preferences.
onDetached
public void onDetached()
Called when the preference hierarchy has been detached from the list of preferences. This can also be called when this preference has been removed from a group that was attached to the list of preferences.
removePreference
public boolean removePreference(@NonNull Preference preference)
Removes a Preference from this group.
Note: This action is not recursive, and will only remove a preference if it exists in this group, ignoring preferences found in nested groups. Use removePreferenceRecursively to recursively find and remove a preference.
| Parameters | |
|---|---|
@NonNull Preference preference |
The preference to remove |
| Returns | |
|---|---|
boolean |
Whether the preference was found and removed |
| See also | |
|---|---|
removePreferenceRecursively |
removePreferenceRecursively
public boolean removePreferenceRecursively(@NonNull CharSequence key)
Recursively finds and removes a Preference from this group or a nested group lower down in the hierarchy. If two Preferences share the same key (not recommended), the first to appear will be removed.
| Parameters | |
|---|---|
@NonNull CharSequence key |
The key of the preference to remove |
| Returns | |
|---|---|
boolean |
Whether the preference was found and removed |
| See also | |
|---|---|
findPreference |
setInitialExpandedChildrenCount
public 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. If some children are hidden an expand button will be provided to show all the hidden children. Any child in any level of the hierarchy that is also a preference group (e.g. preference category) will not be counted towards the limit. But instead the children of such group will be counted. By default, all children will be shown, so the default value of this attribute is equal to Integer.MAX_VALUE.
Note: The group should have a key defined if an expandable preference is present to correctly persist state.
| Parameters | |
|---|---|
int expandedCount |
The number of children that is initially shown initialExpandedChildrenCount |
setOrderingAsAdded
public void setOrderingAsAdded(boolean orderingAsAdded)
Whether to order the 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.
| Parameters | |
|---|---|
boolean orderingAsAdded |
Whether to order according to the order added |
| See also | |
|---|---|
setOrder |
Protected methods
dispatchRestoreInstanceState
protected void dispatchRestoreInstanceState(@NonNull Bundle container)
Called by restoreHierarchyState 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.
dispatchSaveInstanceState
protected void dispatchSaveInstanceState(@NonNull Bundle container)
Called by saveHierarchyState 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.
| See also | |
|---|---|
saveHierarchyState |
|
onSaveInstanceState |
isOnSameScreenAsChildren
protected boolean isOnSameScreenAsChildren()
Whether this preference group should be shown on the same screen as its contained preferences.
| Returns | |
|---|---|
boolean |
|
onPrepareAddPreference
protected boolean onPrepareAddPreference(@NonNull Preference preference)
Prepares a Preference to be added to the group.
| Parameters | |
|---|---|
@NonNull Preference preference |
The preference to add |
| Returns | |
|---|---|
boolean |
Whether to allow adding the preference ( |
onRestoreInstanceState
protected void onRestoreInstanceState(@Nullable Parcelable state)
Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState. This function will never be called with a null state.
| Parameters | |
|---|---|
@Nullable Parcelable state |
The saved state that had previously been returned by |
| See also | |
|---|---|
onSaveInstanceState |
|
restoreHierarchyState |
onSaveInstanceState
protected @NonNull 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. This state should only contain information that is not persistent or can be reconstructed later.
| Returns | |
|---|---|
@NonNull Parcelable |
A Parcelable object containing the current dynamic state of this preference, or |
| See also | |
|---|---|
onRestoreInstanceState |
|
saveHierarchyState |
Extension functions
PreferenceGroupKt.contains
public final boolean PreferenceGroupKt.contains(
@NonNull PreferenceGroup receiver,
@NonNull Preference preference
)
Returns true if preference is found in this preference group.
PreferenceGroupKt.forEach
public final void PreferenceGroupKt.forEach(
@NonNull PreferenceGroup receiver,
@NonNull Function1<@NonNull Preference, Unit> action
)
Performs the given action on each preference in this preference group.
PreferenceGroupKt.forEachIndexed
public final void PreferenceGroupKt.forEachIndexed(
@NonNull PreferenceGroup receiver,
@NonNull Function2<@NonNull Integer, @NonNull Preference, Unit> action
)
Performs the given action on each preference in this preference group, providing its sequential index.
PreferenceGroupKt.get
public final @NonNull Preference PreferenceGroupKt.get(@NonNull PreferenceGroup receiver, int index)
Returns the preference at index.
| Throws | |
|---|---|
IndexOutOfBoundsException |
if index is less than 0 or greater than or equal to the count. |
PreferenceGroupKt.get
public final T <T extends Preference> PreferenceGroupKt.get(
@NonNull PreferenceGroup receiver,
@NonNull CharSequence key
)
Returns the preference with key, or null if no preference with key is found.
PreferenceGroupKt.getChildren
public final @NonNull Sequence<@NonNull Preference> PreferenceGroupKt.getChildren(@NonNull PreferenceGroup receiver)
Returns a Sequence over the preferences in this preference group.
PreferenceGroupKt.getSize
public final int PreferenceGroupKt.getSize(@NonNull PreferenceGroup receiver)
Returns the number of preferences in this preference group.
PreferenceGroupKt.isEmpty
public final boolean PreferenceGroupKt.isEmpty(@NonNull PreferenceGroup receiver)
Returns true if this preference group contains no preferences.
PreferenceGroupKt.isNotEmpty
public final boolean PreferenceGroupKt.isNotEmpty(@NonNull PreferenceGroup receiver)
Returns true if this preference group contains one or more preferences.
PreferenceGroupKt.iterator
public final @NonNull Iterator<@NonNull Preference> PreferenceGroupKt.iterator(@NonNull PreferenceGroup receiver)
Returns a MutableIterator over the preferences in this preference group.
PreferenceGroupKt.minusAssign
public final void PreferenceGroupKt.minusAssign(
@NonNull PreferenceGroup receiver,
@NonNull Preference preference
)
Removes preference from this preference group.
PreferenceGroupKt.plusAssign
public final void PreferenceGroupKt.plusAssign(
@NonNull PreferenceGroup receiver,
@NonNull Preference preference
)
Adds preference to this preference group.