PreferenceGroup
abstract class PreferenceGroup : 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 |
|---|
|
Interface for PreferenceGroup adapters to implement so that |
Public constructors |
|---|
PreferenceGroup(context: Context, attrs: AttributeSet?) |
PreferenceGroup(context: Context, attrs: AttributeSet?, defStyleAttr: Int) |
PreferenceGroup( |
Public functions |
|
|---|---|
Unit |
addItemFromInflater(preference: Preference)Called by the inflater to add an item to this group. |
Boolean |
addPreference(preference: Preference)Adds a |
T? |
<T : Preference?> findPreference(key: CharSequence)Finds a |
Int |
Gets the maximal number of children that are initially shown. |
Preference |
getPreference(index: Int)Returns the |
Int |
Returns the number of children |
Boolean |
Whether this group is ordering preferences in the order they are added. |
Unit |
notifyDependencyChange(disableDependents: Boolean)Notifies any listening dependents of a change that affects the dependency. |
Unit |
Called when the preference hierarchy has been attached to the list of preferences. |
Unit |
Called when the preference hierarchy has been detached from the list of preferences. |
Unit |
Removes all |
Boolean |
removePreference(preference: Preference)Removes a |
Boolean |
Recursively finds and removes a |
Unit |
setInitialExpandedChildrenCount(expandedCount: Int)Sets the maximal number of children that are shown when the preference group is launched where the rest of the children will be hidden. |
Unit |
setOrderingAsAdded(orderingAsAdded: Boolean)Whether to order the |
Protected functions |
|
|---|---|
Unit |
dispatchRestoreInstanceState(container: Bundle)Called by |
Unit |
dispatchSaveInstanceState(container: Bundle)Called by |
Boolean |
Whether this preference group should be shown on the same screen as its contained preferences. |
Boolean |
onPrepareAddPreference(preference: Preference)Prepares a |
Unit |
onRestoreInstanceState(state: Parcelable?)Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by |
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 |
|
|---|---|
operator Boolean |
PreferenceGroup.contains(preference: Preference)Returns |
inline Unit |
PreferenceGroup.forEach(action: (preference: Preference) -> Unit)Performs the given action on each preference in this preference group. |
inline Unit |
PreferenceGroup.forEachIndexed(Performs the given action on each preference in this preference group, providing its sequential index. |
operator Preference |
PreferenceGroup.get(index: Int)Returns the preference at |
inline operator T? |
<T : Preference> PreferenceGroup.get(key: CharSequence)Returns the preference with |
inline Boolean |
Returns true if this preference group contains no preferences. |
inline Boolean |
Returns true if this preference group contains one or more preferences. |
operator Iterator<Preference> |
Returns a |
inline operator Unit |
PreferenceGroup.minusAssign(preference: Preference)Removes |
inline operator Unit |
PreferenceGroup.plusAssign(preference: Preference)Adds |
Extension properties |
|
|---|---|
Sequence<Preference> |
Returns a |
Int |
Returns the number of preferences in this preference group. |
Inherited Constants |
||
|---|---|---|
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
Public constructors
PreferenceGroup
PreferenceGroup(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
PreferenceGroup
PreferenceGroup(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
)
Public functions
addItemFromInflater
fun addItemFromInflater(preference: Preference): Unit
Called by the inflater to add an item to this group.
addPreference
fun addPreference(preference: Preference): Boolean
Adds a Preference at the correct position based on the preference's order.
| Parameters | |
|---|---|
preference: Preference |
The preference to add |
| Returns | |
|---|---|
Boolean |
Whether the preference is now in this group |
findPreference
fun <T : Preference?> findPreference(key: CharSequence): T?
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 | |
|---|---|
key: CharSequence |
The key of the |
| Returns | |
|---|---|
T? |
The |
getInitialExpandedChildrenCount
fun getInitialExpandedChildrenCount(): Int
Gets the maximal number of children that are initially shown.
| Returns | |
|---|---|
Int |
The maximal number of children that are initially shown |
getPreference
fun getPreference(index: Int): Preference
Returns the Preference at a particular index.
| Parameters | |
|---|---|
index: Int |
The index of the |
| Returns | |
|---|---|
Preference |
The |
getPreferenceCount
fun getPreferenceCount(): Int
Returns the number of children Preferences.
| Returns | |
|---|---|
Int |
The number of preference children in this group |
isOrderingAsAdded
fun isOrderingAsAdded(): Boolean
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
fun notifyDependencyChange(disableDependents: Boolean): Unit
Notifies any listening dependents of a change that affects the dependency.
| Parameters | |
|---|---|
disableDependents: Boolean |
Whether this preference should disable its dependents. |
onAttached
fun onAttached(): Unit
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
fun onDetached(): Unit
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
fun removePreference(preference: Preference): Boolean
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 | |
|---|---|
preference: Preference |
The preference to remove |
| Returns | |
|---|---|
Boolean |
Whether the preference was found and removed |
| See also | |
|---|---|
removePreferenceRecursively |
removePreferenceRecursively
fun removePreferenceRecursively(key: CharSequence): Boolean
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 | |
|---|---|
key: CharSequence |
The key of the preference to remove |
| Returns | |
|---|---|
Boolean |
Whether the preference was found and removed |
| See also | |
|---|---|
findPreference |
setInitialExpandedChildrenCount
fun setInitialExpandedChildrenCount(expandedCount: Int): Unit
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 | |
|---|---|
expandedCount: Int |
The number of children that is initially shown |
setOrderingAsAdded
fun setOrderingAsAdded(orderingAsAdded: Boolean): Unit
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 | |
|---|---|
orderingAsAdded: Boolean |
Whether to order according to the order added |
| See also | |
|---|---|
setOrder |
Protected functions
dispatchRestoreInstanceState
protected fun dispatchRestoreInstanceState(container: Bundle): Unit
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.
| Parameters | |
|---|---|
container: Bundle |
The Bundle that holds the previously saved state |
dispatchSaveInstanceState
protected fun dispatchSaveInstanceState(container: Bundle): Unit
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.
| Parameters | |
|---|---|
container: Bundle |
The Bundle in which to save the instance of this preference |
| See also | |
|---|---|
saveHierarchyState |
|
onSaveInstanceState |
isOnSameScreenAsChildren
protected fun isOnSameScreenAsChildren(): Boolean
Whether this preference group should be shown on the same screen as its contained preferences.
| Returns | |
|---|---|
Boolean |
|
onPrepareAddPreference
protected fun onPrepareAddPreference(preference: Preference): Boolean
Prepares a Preference to be added to the group.
| Parameters | |
|---|---|
preference: Preference |
The preference to add |
| Returns | |
|---|---|
Boolean |
Whether to allow adding the preference ( |
onRestoreInstanceState
protected fun onRestoreInstanceState(state: Parcelable?): Unit
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 | |
|---|---|
state: Parcelable? |
The saved state that had previously been returned by |
| See also | |
|---|---|
onSaveInstanceState |
|
restoreHierarchyState |
onSaveInstanceState
protected fun onSaveInstanceState(): 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. This state should only contain information that is not persistent or can be reconstructed later.
| Returns | |
|---|---|
Parcelable |
A Parcelable object containing the current dynamic state of this preference, or |
| See also | |
|---|---|
onRestoreInstanceState |
|
saveHierarchyState |
Extension functions
contains
operator fun PreferenceGroup.contains(preference: Preference): Boolean
Returns true if preference is found in this preference group.
forEach
inline fun PreferenceGroup.forEach(action: (preference: Preference) -> Unit): Unit
Performs the given action on each preference in this preference group.
forEachIndexed
inline fun PreferenceGroup.forEachIndexed(
action: (index: Int, preference: Preference) -> Unit
): Unit
Performs the given action on each preference in this preference group, providing its sequential index.
get
operator fun PreferenceGroup.get(index: Int): Preference
Returns the preference at index.
| Throws | |
|---|---|
kotlin.IndexOutOfBoundsException |
if index is less than 0 or greater than or equal to the count. |
get
inline operator fun <T : Preference> PreferenceGroup.get(key: CharSequence): T?
Returns the preference with key, or null if no preference with key is found.
isEmpty
inline fun PreferenceGroup.isEmpty(): Boolean
Returns true if this preference group contains no preferences.
isNotEmpty
inline fun PreferenceGroup.isNotEmpty(): Boolean
Returns true if this preference group contains one or more preferences.
iterator
operator fun PreferenceGroup.iterator(): Iterator<Preference>
Returns a MutableIterator over the preferences in this preference group.
minusAssign
inline operator fun PreferenceGroup.minusAssign(preference: Preference): Unit
Removes preference from this preference group.
plusAssign
inline operator fun PreferenceGroup.plusAssign(preference: Preference): Unit
Adds preference to this preference group.
Extension properties
children
val PreferenceGroup.children: Sequence<Preference>
Returns a Sequence over the preferences in this preference group.