The Android Developer Challenge is back! Submit your idea before December 2.

TwoStatePreference

abstract class TwoStatePreference : Preference
kotlin.Any
   ↳ androidx.preference.Preference
   ↳ androidx.preference.TwoStatePreference

Common base class for preferences that have two selectable states, save a boolean value, and may have dependent preferences that are enabled/disabled based on the current state.

Summary

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!)

<init>(context: Context!)

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.

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(defaultValue: Any?)

open Unit

Sync a summary holder contained within holder's sub-hierarchy with the correct summary text.

Inherited functions

Properties

Boolean

Public constructors

<init>

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

<init>

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

<init>

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

<init>

TwoStatePreference(context: Context!)

Public methods

getDisableDependentsState

open fun getDisableDependentsState(): Boolean

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 fun getSummaryOff(): CharSequence!

Returns the summary to be shown when unchecked.

Return
CharSequence!: The summary

getSummaryOn

open fun getSummaryOn(): CharSequence!

Returns the summary to be shown when checked.

Return
CharSequence!: The summary

isChecked

open fun isChecked(): Boolean

Returns the checked state.

Return
Boolean: The checked state

setChecked

open fun setChecked(checked: Boolean): Unit

Sets the checked state and saves it.

Parameters
checked Boolean: The checked state

setDisableDependentsState

open fun setDisableDependentsState(disableDependentsState: Boolean): Unit

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 fun setSummaryOff(summary: CharSequence!): Unit

Sets the summary to be shown when unchecked.

For more complex configuration of this preference's summary, you should use a Preference.SummaryProvider

Parameters
summary CharSequence!: The summary to be shown when unchecked

setSummaryOff

open fun setSummaryOff(summaryResId: Int): Unit
Parameters
summaryResId Int: The summary as a resource

setSummaryOn

open fun setSummaryOn(summary: CharSequence!): Unit

Sets the summary to be shown when checked.

For more complex configuration of this preference's summary, you should use a Preference.SummaryProvider

Parameters
summary CharSequence!: The summary to be shown when checked

setSummaryOn

open fun setSummaryOn(summaryResId: Int): Unit
Parameters
summaryResId Int: The summary as a resource

shouldDisableDependents

open fun shouldDisableDependents(): Boolean

Protected methods

onClick

protected open fun onClick(): Unit

onGetDefaultValue

protected open fun onGetDefaultValue(a: TypedArray!, index: Int): Any!

onRestoreInstanceState

protected open fun onRestoreInstanceState(state: Parcelable!): Unit

onSaveInstanceState

protected open fun onSaveInstanceState(): Parcelable!

onSetInitialValue

protected open fun onSetInitialValue(defaultValue: Any?): Unit

syncSummaryView

protected open fun syncSummaryView(holder: PreferenceViewHolder!): Unit

Sync a summary holder contained within holder's sub-hierarchy with the correct summary text.

Parameters
holder PreferenceViewHolder!: A PreferenceViewHolder which holds a reference to the summary view

Properties

mChecked

protected var mChecked: Boolean