TwoStatePreference
abstract classTwoStatePreference: Preference
| kotlin.Any | ||
| ↳ | android.preference.Preference | |
| ↳ | android.preference.TwoStatePreference | |
Common base class for preferences that have two selectable states, persist a boolean value in SharedPreferences, and may have dependent preferences that are enabled/disabled based on the current state.
Summary
| Inherited XML attributes | |
|---|---|
| Inherited constants | |
|---|---|
| Public constructors | |
|---|---|
TwoStatePreference(context: Context!) |
|
TwoStatePreference(context: Context!, attrs: AttributeSet!) |
|
TwoStatePreference(context: Context!, attrs: AttributeSet!, defStyleAttr: Int) |
|
TwoStatePreference(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int) |
|
| Public methods | |
|---|---|
| open Boolean |
Returns whether dependents are disabled when this preference is on ( |
| open CharSequence! |
Returns the summary to be shown when unchecked. |
| open CharSequence! |
Returns the summary to be shown when checked. |
| open Boolean |
Returns the checked state. |
| open Unit |
setChecked(checked: Boolean)Sets the checked state and saves it to the |
| open Unit |
setDisableDependentsState(disableDependentsState: Boolean)Sets whether dependents are disabled when this preference is on ( |
| open Unit |
setSummaryOff(summaryResId: Int) |
| open Unit |
setSummaryOff(summary: CharSequence!)Sets the summary to be shown when unchecked. |
| open Unit |
setSummaryOn(summaryResId: Int) |
| open Unit |
setSummaryOn(summary: CharSequence!)Sets the summary to be shown when checked. |
| open Boolean |
Checks whether this preference's dependents should currently be disabled. |
| Protected methods | |
|---|---|
| open Unit |
onClick()Processes a click on the preference. |
| open Any! |
onGetDefaultValue(a: TypedArray!, index: Int)Called when a Preference is being inflated and the default value attribute needs to be read. |
| open Unit |
onRestoreInstanceState(state: Parcelable!)Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by |
| open 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. |
| open Unit |
onSetInitialValue(restoreValue: Boolean, defaultValue: Any!)Implement this to set the initial value of the Preference. |
| Inherited functions | |
|---|---|
Public constructors
TwoStatePreference
TwoStatePreference(
context: Context!,
attrs: AttributeSet!)
TwoStatePreference
TwoStatePreference(
context: Context!,
attrs: AttributeSet!,
defStyleAttr: Int)
TwoStatePreference
TwoStatePreference(
context: Context!,
attrs: AttributeSet!,
defStyleAttr: Int,
defStyleRes: Int)
Public methods
getDisableDependentsState
open fungetDisableDependentsState(): Boolean
Deprecated: Deprecated in Java.
Returns whether dependents are disabled when this preference is on (true) or when this preference is off (false).
| Return | |
|---|---|
Boolean |
Whether dependents are disabled when this preference is on (true) or when this preference is off (false). |
getSummaryOff
open fungetSummaryOff(): CharSequence!
Deprecated: Deprecated in Java.
Returns the summary to be shown when unchecked.
| Return | |
|---|---|
CharSequence! |
The summary. |
getSummaryOn
open fungetSummaryOn(): CharSequence!
Deprecated: Deprecated in Java.
Returns the summary to be shown when checked.
| Return | |
|---|---|
CharSequence! |
The summary. |
isChecked
open funisChecked(): Boolean
Deprecated: Deprecated in Java.
Returns the checked state.
| Return | |
|---|---|
Boolean |
The checked state. |
setChecked
open funsetChecked(checked: Boolean): Unit
Deprecated: Deprecated in Java.
Sets the checked state and saves it to the SharedPreferences.
| Parameters | |
|---|---|
checked |
Boolean: The checked state. |
setDisableDependentsState
open funsetDisableDependentsState(disableDependentsState: Boolean): Unit
Deprecated: Deprecated in Java.
Sets whether dependents are disabled when this preference is on (true) or when this preference is off (false).
| Parameters | |
|---|---|
disableDependentsState |
Boolean: The preference state that should disable dependents. |
setSummaryOff
open funsetSummaryOff(summaryResId: Int): Unit
Deprecated: Deprecated in Java.
| Parameters | |
|---|---|
summaryResId |
Int: The summary as a resource. |
See Also
setSummaryOff
open funsetSummaryOff(summary: CharSequence!): Unit
Deprecated: Deprecated in Java.
Sets the summary to be shown when unchecked.
| Parameters | |
|---|---|
summary |
CharSequence!: The summary to be shown when unchecked. |
setSummaryOn
open funsetSummaryOn(summaryResId: Int): Unit
Deprecated: Deprecated in Java.
| Parameters | |
|---|---|
summaryResId |
Int: The summary as a resource. |
See Also
setSummaryOn
open funsetSummaryOn(summary: CharSequence!): Unit
Deprecated: Deprecated in Java.
Sets the summary to be shown when checked.
| Parameters | |
|---|---|
summary |
CharSequence!: The summary to be shown when checked. |
shouldDisableDependents
open funshouldDisableDependents(): Boolean
Deprecated: Deprecated in Java.
Checks whether this preference's dependents should currently be disabled.
| Return | |
|---|---|
Boolean |
True if the dependents should be disabled, otherwise false. |
Protected methods
onClick
protected open funonClick(): Unit
Deprecated: Deprecated in Java.
Processes a click on the preference. This includes saving the value to the SharedPreferences. However, the overridden method should call callChangeListener(java.lang.Object) to make sure the client wants to update the preference's state with the new value.
onGetDefaultValue
protected open funonGetDefaultValue(
a: TypedArray!,
index: Int
): Any!
Deprecated: Deprecated in Java.
Called when a Preference is being inflated and the default value attribute needs to be read. Since different Preference types have different value types, the subclass should get and return the default value which will be its value type.
For example, if the value type is String, the body of the method would proxy to TypedArray.getString(int).
| Parameters | |
|---|---|
a |
TypedArray!: The set of attributes. |
index |
Int: The index of the default value attribute. |
| Return | |
|---|---|
Any! |
The default value of this preference type. |
onRestoreInstanceState
protected open funonRestoreInstanceState(state: Parcelable!): Unit
Deprecated: Deprecated in Java.
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 onSaveInstanceState. |
onSaveInstanceState
protected open funonSaveInstanceState(): Parcelable!
Deprecated: Deprecated in Java.
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.
| Return | |
|---|---|
Parcelable! |
A Parcelable object containing the current dynamic state of this Preference, or null if there is nothing interesting to save. The default implementation returns null. |
onSetInitialValue
protected open funonSetInitialValue(
restoreValue: Boolean,
defaultValue: Any!
): Unit
Deprecated: Deprecated in Java.
Implement this to set the initial value of the Preference.
If restorePersistedValue is true, you should restore the Preference value from the android.content.SharedPreferences. If restorePersistedValue is false, you should set the Preference value to defaultValue that is given (and possibly store to SharedPreferences if shouldPersist() is true).
In case of using PreferenceDataStore, the restorePersistedValue is always true. But the default value (if provided) is set.
This may not always be called. One example is if it should not persist but there is no default value given.
| Parameters | |
|---|---|
restorePersistedValue |
True to restore the persisted value; false to use the given defaultValue. |
defaultValue |
Any!: The default value for this Preference. Only use this if restorePersistedValue is false. |