Added in API level 14
Deprecated in API level 29

TwoStatePreference

abstract class TwoStatePreference : 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!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

TwoStatePreference(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

Public methods
open Boolean

Returns whether dependents are disabled when this preference is on (true) or when this preference is off (false).

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 SharedPreferences.

open Unit
setDisableDependentsState(disableDependentsState: Boolean)

Sets whether dependents are disabled when this preference is on (true) or when this preference is off (false).

open Unit

Sets the summary to be shown when unchecked.

open Unit
setSummaryOff(summaryResId: Int)

open Unit

Sets the summary to be shown when checked.

open Unit
setSummaryOn(summaryResId: Int)

open Boolean

Protected methods
open Unit

open Any!

open Unit

open Parcelable!

open Unit
onSetInitialValue(restoreValue: Boolean, defaultValue: Any!)

Inherited functions

Public constructors

TwoStatePreference

Added in API level 14
TwoStatePreference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

TwoStatePreference

Added in API level 14
TwoStatePreference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

TwoStatePreference

Added in API level 14
TwoStatePreference(
    context: Context!,
    attrs: AttributeSet!)

TwoStatePreference

Added in API level 14
TwoStatePreference(context: Context!)

Public methods

getDisableDependentsState

Added in API level 14
open fun getDisableDependentsState(): 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

Added in API level 14
open fun getSummaryOff(): CharSequence!

Deprecated: Deprecated in Java.

Returns the summary to be shown when unchecked.

Return
CharSequence! The summary.

getSummaryOn

Added in API level 14
open fun getSummaryOn(): CharSequence!

Deprecated: Deprecated in Java.

Returns the summary to be shown when checked.

Return
CharSequence! The summary.

isChecked

Added in API level 14
open fun isChecked(): Boolean

Deprecated: Deprecated in Java.

Returns the checked state.

Return
Boolean The checked state.

setChecked

Added in API level 14
open fun setChecked(checked: Boolean): Unit

Deprecated: Deprecated in Java.

Sets the checked state and saves it to the SharedPreferences.

Parameters
checked Boolean: The checked state.

setDisableDependentsState

Added in API level 14
open fun setDisableDependentsState(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

Added in API level 14
open fun setSummaryOff(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.

setSummaryOff

Added in API level 14
open fun setSummaryOff(summaryResId: Int): Unit

Deprecated: Deprecated in Java.

Parameters
summaryResId Int: The summary as a resource.

setSummaryOn

Added in API level 14
open fun setSummaryOn(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.

setSummaryOn

Added in API level 14
open fun setSummaryOn(summaryResId: Int): Unit

Deprecated: Deprecated in Java.

Parameters
summaryResId Int: The summary as a resource.

shouldDisableDependents

Added in API level 14
open fun shouldDisableDependents(): Boolean

Deprecated: Deprecated in Java.

Return
Boolean True if the dependents should be disabled, otherwise false.

Protected methods

onClick

Added in API level 14
protected open fun onClick(): Unit

Deprecated: Deprecated in Java.

onGetDefaultValue

Added in API level 14
protected open fun onGetDefaultValue(
    a: TypedArray!,
    index: Int
): Any!

Deprecated: Deprecated in Java.

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

Added in API level 14
protected open fun onRestoreInstanceState(state: Parcelable!): Unit

Deprecated: Deprecated in Java.

Parameters
state Parcelable!: The saved state that had previously been returned by onSaveInstanceState.

onSaveInstanceState

Added in API level 14
protected open fun onSaveInstanceState(): Parcelable!

Deprecated: Deprecated in Java.

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

Added in API level 14
protected open fun onSetInitialValue(
    restoreValue: Boolean,
    defaultValue: Any!
): Unit

Deprecated: Deprecated in Java.

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.