PreferenceGroup
abstract class PreferenceGroup : Preference
kotlin.Any | ||
↳ | androidx.preference.Preference | |
↳ | androidx.preference.PreferenceGroup |
A container for multiple Preference
s. It is a base class for preference objects that are parents, such as PreferenceCategory
and PreferenceScreen
.
Summary
Nested classes |
|
---|---|
abstract |
Interface for PreferenceGroup adapters to implement so that |
Inherited constants |
|
---|---|
Public constructors |
|
---|---|
<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int) |
|
<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int) |
|
<init>(context: Context!, attrs: AttributeSet!) |
Public methods |
|
---|---|
open Unit |
addItemFromInflater(preference: Preference!) Called by the inflater to add an item to this group. |
open Boolean |
addPreference(preference: Preference!) Adds a |
open T? |
findPreference(@NonNull key: CharSequence) Finds a |
open Int |
Gets the maximal number of children that are initially shown. |
open Preference! |
getPreference(index: Int) Returns the |
open Int |
Returns the number of children |
open Boolean |
Whether this group is ordering preferences in the order they are added. |
open Unit |
notifyDependencyChange(disableDependents: Boolean) |
open Unit | |
open Unit | |
open Unit |
Removes all |
open Boolean |
removePreference(preference: Preference!) Removes a |
open Boolean |
removePreferenceRecursively(@NonNull key: CharSequence) Recursively finds and removes a |
open 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. |
open Unit |
setOrderingAsAdded(orderingAsAdded: Boolean) Whether to order the |
Protected methods |
|
---|---|
open Unit |
dispatchRestoreInstanceState(container: Bundle!) |
open Unit |
dispatchSaveInstanceState(container: Bundle!) |
open Boolean |
Whether this preference group should be shown on the same screen as its contained preferences. |
open Boolean |
onPrepareAddPreference(preference: Preference!) Prepares a |
open Unit |
onRestoreInstanceState(state: Parcelable!) |
open Parcelable! |
Inherited functions |
|
---|---|
Extension functions |
||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
From androidx.preference
|
Extension properties |
||||
---|---|---|---|---|
From androidx.preference
|
Public constructors
<init>
PreferenceGroup(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)
<init>
PreferenceGroup(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)
<init>
PreferenceGroup(context: Context!, attrs: AttributeSet!)
Public methods
addItemFromInflater
open fun addItemFromInflater(preference: Preference!): Unit
Called by the inflater to add an item to this group.
addPreference
open 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 |
Return | |
---|---|
Boolean: Whether the preference is now in this group |
findPreference
@Nullable open fun <T : Preference!> findPreference(@NonNull key: CharSequence): T?
Finds a Preference
based on its key. If two Preference
s 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 PreferenceGroup
s.
Parameters | |
---|---|
key |
CharSequence: The key of the Preference to retrieve |
Return | |
---|---|
T?: The Preference with the key, or null |
getInitialExpandedChildrenCount
open fun getInitialExpandedChildrenCount(): Int
Gets the maximal number of children that are initially shown.
Return | |
---|---|
Int: The maximal number of children that are initially shown androidx.preference.R.attr#initialExpandedChildrenCount |
getPreference
open fun getPreference(index: Int): Preference!
Returns the Preference
at a particular index.
Parameters | |
---|---|
index |
Int: The index of the Preference to retrieve |
Return | |
---|---|
Preference!: The Preference |
getPreferenceCount
open fun getPreferenceCount(): Int
Returns the number of children Preference
s.
Return | |
---|---|
Int: The number of preference children in this group |
isOrderingAsAdded
open fun isOrderingAsAdded(): Boolean
Whether this group is ordering preferences in the order they are added.
Return | |
---|---|
Boolean: Whether this group orders based on the order the children are added |
See Also
onAttached
open fun onAttached(): Unit
onDetached
open fun onDetached(): Unit
removePreference
open 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(CharSequence)
to recursively find and remove a preference.
Parameters | |
---|---|
preference |
Preference!: The preference to remove |
Return | |
---|---|
Boolean: Whether the preference was found and removed |
removePreferenceRecursively
open fun removePreferenceRecursively(@NonNull key: CharSequence): Boolean
Recursively finds and removes a Preference
from this group or a nested group lower down in the hierarchy. If two Preference
s share the same key (not recommended), the first to appear will be removed.
Parameters | |
---|---|
key |
CharSequence: The key of the preference to remove |
Return | |
---|---|
Boolean: Whether the preference was found and removed |
See Also
setInitialExpandedChildrenCount
open 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 androidx.preference.R.attr#initialExpandedChildrenCount |
setOrderingAsAdded
open 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
Protected methods
dispatchRestoreInstanceState
protected open fun dispatchRestoreInstanceState(container: Bundle!): Unit
isOnSameScreenAsChildren
protected open fun isOnSameScreenAsChildren(): Boolean
Whether this preference group should be shown on the same screen as its contained preferences.
Return | |
---|---|
Boolean: true if the contained preferences should be shown on the same screen as this preference. |
onPrepareAddPreference
protected open fun onPrepareAddPreference(preference: Preference!): Boolean
Prepares a Preference
to be added to the group.
Parameters | |
---|---|
preference |
Preference!: The preference to add |
Return | |
---|---|
Boolean: Whether to allow adding the preference (true ), or not (false ) |
onRestoreInstanceState
protected open fun onRestoreInstanceState(state: Parcelable!): Unit
onSaveInstanceState
protected open fun onSaveInstanceState(): Parcelable!