# TwoStatePreference

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)   
Deprecated in [API level
29](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary: [Inherited XML Attrs](https://developer.android.com/reference/android/preference/TwoStatePreference#inhattrs) \| [Inherited Constants](https://developer.android.com/reference/android/preference/TwoStatePreference#inhconstants) \| [Ctors](https://developer.android.com/reference/android/preference/TwoStatePreference#pubctors) \| [Methods](https://developer.android.com/reference/android/preference/TwoStatePreference#pubmethods) \| [Protected Methods](https://developer.android.com/reference/android/preference/TwoStatePreference#promethods) \| [Inherited Methods](https://developer.android.com/reference/android/preference/TwoStatePreference#inhmethods)  

# TwoStatePreference

*** ** * ** ***

[Kotlin](https://developer.android.com/reference/kotlin/android/preference/TwoStatePreference "View this page in Kotlin") \|Java


`
public


abstract
class
TwoStatePreference
`


`


`

`

extends `[Preference](https://developer.android.com/reference/android/preference/Preference)`


`

`


`

|---|---|---------------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) |||
| ↳ | [android.preference.Preference](https://developer.android.com/reference/android/preference/Preference) ||
|   | ↳ | android.preference.TwoStatePreference |

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known direct subclasses [CheckBoxPreference](https://developer.android.com/reference/android/preference/CheckBoxPreference), [SwitchPreference](https://developer.android.com/reference/android/preference/SwitchPreference) |-----------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [CheckBoxPreference](https://developer.android.com/reference/android/preference/CheckBoxPreference) | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | | [SwitchPreference](https://developer.android.com/reference/android/preference/SwitchPreference)     | *This class was deprecated in API level 29. Use the [AndroidX](https://developer.android.com/jetpack/androidx) [Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on using the AndroidX Preference Library see [Settings](https://developer.android.com/guide/topics/ui/settings).* | |

<br />

*** ** * ** ***


**This class was deprecated
in API level 29.**   

Use the [AndroidX](https://developer.android.com/jetpack/androidx)
[Preference Library](https://developer.android.com/reference/androidx/preference/package-summary) for consistent behavior across all devices. For more information on
using the AndroidX Preference Library see
[Settings](https://developer.android.com/guide/topics/ui/settings).

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 |
|------------------------------|---|
| From class [android.preference.Preference](https://developer.android.com/reference/android/preference/Preference) |-------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------| | [`android:defaultValue`](https://developer.android.com/reference/android/preference/Preference#attr_android:defaultValue)           | The default value for the preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage. | | [`android:dependency`](https://developer.android.com/reference/android/preference/Preference#attr_android:dependency)               | The key of another Preference that this Preference will depend on.                                                                                                   | | [`android:enabled`](https://developer.android.com/reference/android/preference/Preference#attr_android:enabled)                     | Whether the Preference is enabled.                                                                                                                                   | | [`android:fragment`](https://developer.android.com/reference/android/preference/Preference#attr_android:fragment)                   | When used inside of a modern PreferenceActivity, this declares a new PreferenceFragment to be shown when the user selects this item.                                 | | [`android:icon`](https://developer.android.com/reference/android/preference/Preference#attr_android:icon)                           | The optional icon for the preference.                                                                                                                                | | [`android:iconSpaceReserved`](https://developer.android.com/reference/android/preference/Preference#attr_android:iconSpaceReserved) | Whether the space for the preference icon view will be reserved.                                                                                                     | | [`android:key`](https://developer.android.com/reference/android/preference/Preference#attr_android:key)                             | The key to store the Preference value.                                                                                                                               | | [`android:layout`](https://developer.android.com/reference/android/preference/Preference#attr_android:layout)                       | The layout for the Preference in a PreferenceActivity screen.                                                                                                        | | [`android:order`](https://developer.android.com/reference/android/preference/Preference#attr_android:order)                         | The order for the Preference (lower values are to be ordered first).                                                                                                 | | [`android:persistent`](https://developer.android.com/reference/android/preference/Preference#attr_android:persistent)               | Whether the Preference stores its value to the storage.                                                                                                              | | [`android:recycleEnabled`](https://developer.android.com/reference/android/preference/Preference#attr_android:recycleEnabled)       | Whether the preference has enabled to have its view recycled when used in the list view.                                                                             | | [`android:selectable`](https://developer.android.com/reference/android/preference/Preference#attr_android:selectable)               | Whether the Preference is selectable.                                                                                                                                | | [`android:shouldDisableView`](https://developer.android.com/reference/android/preference/Preference#attr_android:shouldDisableView) | Whether the view of this Preference should be disabled when this Preference is disabled.                                                                             | | [`android:singleLineTitle`](https://developer.android.com/reference/android/preference/Preference#attr_android:singleLineTitle)     | Whether to use single line for the preference title text.                                                                                                            | | [`android:summary`](https://developer.android.com/reference/android/preference/Preference#attr_android:summary)                     | The summary for the Preference.                                                                                                                                      | | [`android:title`](https://developer.android.com/reference/android/preference/Preference#attr_android:title)                         | The title for the Preference.                                                                                                                                        | | [`android:widgetLayout`](https://developer.android.com/reference/android/preference/Preference#attr_android:widgetLayout)           | The layout for the controllable widget portion of a Preference.                                                                                                      | ||

|                                                                                                                                                                                                                                                                                                                     ### Inherited constants                                                                                                                                                                                                                                                                                                                     |
|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| From class [android.preference.Preference](https://developer.android.com/reference/android/preference/Preference) |-------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | `int` | [DEFAULT_ORDER](https://developer.android.com/reference/android/preference/Preference#DEFAULT_ORDER) Specify for [setOrder(int)](https://developer.android.com/reference/android/preference/Preference#setOrder(int)) if a specific order is not required. | |

|                                                                                                                                                                                                 ### Public constructors                                                                                                                                                                                                 ||
|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[TwoStatePreference](https://developer.android.com/reference/android/preference/TwoStatePreference#TwoStatePreference(android.content.Context))`(`[Context](https://developer.android.com/reference/android/content/Context)` context) `                                                                                                                                                                          |
| ` `[TwoStatePreference](https://developer.android.com/reference/android/preference/TwoStatePreference#TwoStatePreference(android.content.Context,%20android.util.AttributeSet))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, `[AttributeSet](https://developer.android.com/reference/android/util/AttributeSet)` attrs) `                                                  |
| ` `[TwoStatePreference](https://developer.android.com/reference/android/preference/TwoStatePreference#TwoStatePreference(android.content.Context,%20android.util.AttributeSet,%20int))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, `[AttributeSet](https://developer.android.com/reference/android/util/AttributeSet)` attrs, int defStyleAttr) `                         |
| ` `[TwoStatePreference](https://developer.android.com/reference/android/preference/TwoStatePreference#TwoStatePreference(android.content.Context,%20android.util.AttributeSet,%20int,%20int))`(`[Context](https://developer.android.com/reference/android/content/Context)` context, `[AttributeSet](https://developer.android.com/reference/android/util/AttributeSet)` attrs, int defStyleAttr, int defStyleRes) ` |

|                                                                                                                                                                                    ### Public methods                                                                                                                                                                                     ||
|-----------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` boolean`                                                                        | ` `[getDisableDependentsState](https://developer.android.com/reference/android/preference/TwoStatePreference#getDisableDependentsState())`() ` Returns whether dependents are disabled when this preference is on (`true`) or when this preference is off (`false`).                                   |
| ` `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[getSummaryOff](https://developer.android.com/reference/android/preference/TwoStatePreference#getSummaryOff())`() ` Returns the summary to be shown when unchecked.                                                                                                                                 |
| ` `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | ` `[getSummaryOn](https://developer.android.com/reference/android/preference/TwoStatePreference#getSummaryOn())`() ` Returns the summary to be shown when checked.                                                                                                                                     |
| ` boolean`                                                                        | ` `[isChecked](https://developer.android.com/reference/android/preference/TwoStatePreference#isChecked())`() ` Returns the checked state.                                                                                                                                                              |
| ` void`                                                                           | ` `[setChecked](https://developer.android.com/reference/android/preference/TwoStatePreference#setChecked(boolean))`(boolean checked) ` Sets the checked state and saves it to the [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences).                      |
| ` void`                                                                           | ` `[setDisableDependentsState](https://developer.android.com/reference/android/preference/TwoStatePreference#setDisableDependentsState(boolean))`(boolean disableDependentsState) ` Sets whether dependents are disabled when this preference is on (`true`) or when this preference is off (`false`). |
| ` void`                                                                           | ` `[setSummaryOff](https://developer.android.com/reference/android/preference/TwoStatePreference#setSummaryOff(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` summary) ` Sets the summary to be shown when unchecked.                      |
| ` void`                                                                           | ` `[setSummaryOff](https://developer.android.com/reference/android/preference/TwoStatePreference#setSummaryOff(int))`(int summaryResId) `                                                                                                                                                              |
| ` void`                                                                           | ` `[setSummaryOn](https://developer.android.com/reference/android/preference/TwoStatePreference#setSummaryOn(int))`(int summaryResId) `                                                                                                                                                                |
| ` void`                                                                           | ` `[setSummaryOn](https://developer.android.com/reference/android/preference/TwoStatePreference#setSummaryOn(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` summary) ` Sets the summary to be shown when checked.                          |
| ` boolean`                                                                        | ` `[shouldDisableDependents](https://developer.android.com/reference/android/preference/TwoStatePreference#shouldDisableDependents())`() ` Checks whether this preference's dependents should currently be disabled.                                                                                   |

|                                                                                                                                                                                                                                                                           ### Protected methods                                                                                                                                                                                                                                                                            ||
|--------------------------------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` void`                                                                        | ` `[onClick](https://developer.android.com/reference/android/preference/TwoStatePreference#onClick())`() ` Processes a click on the preference.                                                                                                                                                                                                                                                                                                                                            |
| ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[onGetDefaultValue](https://developer.android.com/reference/android/preference/TwoStatePreference#onGetDefaultValue(android.content.res.TypedArray,%20int))`(`[TypedArray](https://developer.android.com/reference/android/content/res/TypedArray)` a, int index) ` Called when a Preference is being inflated and the default value attribute needs to be read.                                                                                                                        |
| ` void`                                                                        | ` `[onRestoreInstanceState](https://developer.android.com/reference/android/preference/TwoStatePreference#onRestoreInstanceState(android.os.Parcelable))`(`[Parcelable](https://developer.android.com/reference/android/os/Parcelable)` state) ` Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by [onSaveInstanceState()](https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()). |
| ` `[Parcelable](https://developer.android.com/reference/android/os/Parcelable) | ` `[onSaveInstanceState](https://developer.android.com/reference/android/preference/TwoStatePreference#onSaveInstanceState())`() ` 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.                                                                                                                                                                                                     |
| ` void`                                                                        | ` `[onSetInitialValue](https://developer.android.com/reference/android/preference/TwoStatePreference#onSetInitialValue(boolean,%20java.lang.Object))`(boolean restoreValue, `[Object](https://developer.android.com/reference/java/lang/Object)` defaultValue) ` Implement this to set the initial value of the Preference.                                                                                                                                                                |

| ### Inherited methods |
|-----------------------|---|
| From class ` `[android.preference.Preference](https://developer.android.com/reference/android/preference/Preference)` ` |----------------------------------------------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` boolean`                                                                                                                                   | ` `[callChangeListener](https://developer.android.com/reference/android/preference/Preference#callChangeListener(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` newValue) ` Call this method after the user changes the preference, but before the internal state is set.                                                                                                                                                                                                                                 | | ` int`                                                                                                                                       | ` `[compareTo](https://developer.android.com/reference/android/preference/Preference#compareTo(android.preference.Preference))`(`[Preference](https://developer.android.com/reference/android/preference/Preference)` another) ` Compares Preference objects based on order (if set), otherwise alphabetically on the titles.                                                                                                                                                                                                                       | | ` `[Preference](https://developer.android.com/reference/android/preference/Preference)                                                       | ` `[findPreferenceInHierarchy](https://developer.android.com/reference/android/preference/Preference#findPreferenceInHierarchy(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` key) ` Finds a Preference in this hierarchy (the whole thing, even above/below your [PreferenceScreen](https://developer.android.com/reference/android/preference/PreferenceScreen) screen break) with the given key.                                                                                                       | | ` `[Context](https://developer.android.com/reference/android/content/Context)                                                                | ` `[getContext](https://developer.android.com/reference/android/preference/Preference#getContext())`() ` Returns the [Context](https://developer.android.com/reference/android/content/Context) of this Preference.                                                                                                                                                                                                                                                                                                                                 | | ` `[String](https://developer.android.com/reference/java/lang/String)                                                                        | ` `[getDependency](https://developer.android.com/reference/android/preference/Preference#getDependency())`() ` Returns the key of the dependency on this Preference.                                                                                                                                                                                                                                                                                                                                                                                | | ` `[SharedPreferences.Editor](https://developer.android.com/reference/android/content/SharedPreferences.Editor)                              | ` `[getEditor](https://developer.android.com/reference/android/preference/Preference#getEditor())`() ` Returns an [SharedPreferences.Editor](https://developer.android.com/reference/android/content/SharedPreferences.Editor) where this Preference can save its value(s).                                                                                                                                                                                                                                                                         | | ` `[Bundle](https://developer.android.com/reference/android/os/Bundle)                                                                       | ` `[getExtras](https://developer.android.com/reference/android/preference/Preference#getExtras())`() ` Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one.                                                                                                                                                                                                                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)                                                                        | ` `[getFragment](https://developer.android.com/reference/android/preference/Preference#getFragment())`() ` Return the fragment class name associated with this Preference.                                                                                                                                                                                                                                                                                                                                                                          | | ` `[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable)                                                    | ` `[getIcon](https://developer.android.com/reference/android/preference/Preference#getIcon())`() ` Returns the icon of this Preference.                                                                                                                                                                                                                                                                                                                                                                                                             | | ` `[Intent](https://developer.android.com/reference/android/content/Intent)                                                                  | ` `[getIntent](https://developer.android.com/reference/android/preference/Preference#getIntent())`() ` Return the [Intent](https://developer.android.com/reference/android/content/Intent) associated with this Preference.                                                                                                                                                                                                                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)                                                                        | ` `[getKey](https://developer.android.com/reference/android/preference/Preference#getKey())`() ` Gets the key for this Preference, which is also the key used for storing values into [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences) or [PreferenceDataStore](https://developer.android.com/reference/android/preference/PreferenceDataStore).                                                                                                                                                      | | ` int`                                                                                                                                       | ` `[getLayoutResource](https://developer.android.com/reference/android/preference/Preference#getLayoutResource())`() ` Gets the layout resource that will be shown as the [View](https://developer.android.com/reference/android/view/View) for this Preference.                                                                                                                                                                                                                                                                                    | | ` `[Preference.OnPreferenceChangeListener](https://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener) | ` `[getOnPreferenceChangeListener](https://developer.android.com/reference/android/preference/Preference#getOnPreferenceChangeListener())`() ` Returns the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).                                                                                                                                                                                                                                                                     | | ` `[Preference.OnPreferenceClickListener](https://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener)   | ` `[getOnPreferenceClickListener](https://developer.android.com/reference/android/preference/Preference#getOnPreferenceClickListener())`() ` Returns the callback to be invoked when this Preference is clicked.                                                                                                                                                                                                                                                                                                                                    | | ` int`                                                                                                                                       | ` `[getOrder](https://developer.android.com/reference/android/preference/Preference#getOrder())`() ` Gets the order of this Preference with respect to other Preference objects on the same level.                                                                                                                                                                                                                                                                                                                                                  | | ` `[PreferenceGroup](https://developer.android.com/reference/android/preference/PreferenceGroup)                                             | ` `[getParent](https://developer.android.com/reference/android/preference/Preference#getParent())`() ` Returns the [PreferenceGroup](https://developer.android.com/reference/android/preference/PreferenceGroup) which is this Preference assigned to or `null` if this preference is not assigned to any group or is a root Preference.                                                                                                                                                                                                            | | ` boolean`                                                                                                                                   | ` `[getPersistedBoolean](https://developer.android.com/reference/android/preference/Preference#getPersistedBoolean(boolean))`(boolean defaultReturnValue) ` Attempts to get a persisted boolean if this Preference is persistent.                                                                                                                                                                                                                                                                                                                   | | ` float`                                                                                                                                     | ` `[getPersistedFloat](https://developer.android.com/reference/android/preference/Preference#getPersistedFloat(float))`(float defaultReturnValue) ` Attempts to get a persisted float if this Preference is persistent.                                                                                                                                                                                                                                                                                                                             | | ` int`                                                                                                                                       | ` `[getPersistedInt](https://developer.android.com/reference/android/preference/Preference#getPersistedInt(int))`(int defaultReturnValue) ` Attempts to get a persisted int if this Preference is persistent.                                                                                                                                                                                                                                                                                                                                       | | ` long`                                                                                                                                      | ` `[getPersistedLong](https://developer.android.com/reference/android/preference/Preference#getPersistedLong(long))`(long defaultReturnValue) ` Attempts to get a persisted long if this Preference is persistent.                                                                                                                                                                                                                                                                                                                                  | | ` `[String](https://developer.android.com/reference/java/lang/String)                                                                        | ` `[getPersistedString](https://developer.android.com/reference/android/preference/Preference#getPersistedString(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` defaultReturnValue) ` Attempts to get a persisted String if this Preference is persistent.                                                                                                                                                                                                                                                | | ` `[Set](https://developer.android.com/reference/java/util/Set)`<`[String](https://developer.android.com/reference/java/lang/String)`>`      | ` `[getPersistedStringSet](https://developer.android.com/reference/android/preference/Preference#getPersistedStringSet(java.util.Set<java.lang.String>))`(`[Set](https://developer.android.com/reference/java/util/Set)`<`[String](https://developer.android.com/reference/java/lang/String)`> defaultReturnValue) ` Attempts to get a persisted set of Strings if this Preference is persistent.                                                                                                                                                   | | ` `[PreferenceDataStore](https://developer.android.com/reference/android/preference/PreferenceDataStore)                                     | ` `[getPreferenceDataStore](https://developer.android.com/reference/android/preference/Preference#getPreferenceDataStore())`() ` Returns [PreferenceDataStore](https://developer.android.com/reference/android/preference/PreferenceDataStore) used by this Preference.                                                                                                                                                                                                                                                                             | | ` `[PreferenceManager](https://developer.android.com/reference/android/preference/PreferenceManager)                                         | ` `[getPreferenceManager](https://developer.android.com/reference/android/preference/Preference#getPreferenceManager())`() ` Gets the [PreferenceManager](https://developer.android.com/reference/android/preference/PreferenceManager) that manages this Preference object's tree.                                                                                                                                                                                                                                                                 | | ` `[SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences)                                            | ` `[getSharedPreferences](https://developer.android.com/reference/android/preference/Preference#getSharedPreferences())`() ` Returns the [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences) where this Preference can read its value(s).                                                                                                                                                                                                                                                                | | ` boolean`                                                                                                                                   | ` `[getShouldDisableView](https://developer.android.com/reference/android/preference/Preference#getShouldDisableView())`() ` Checks whether this Preference should disable its view when it's action is disabled.                                                                                                                                                                                                                                                                                                                                   | | ` `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)                                                            | ` `[getSummary](https://developer.android.com/reference/android/preference/Preference#getSummary())`() ` Returns the summary of this Preference.                                                                                                                                                                                                                                                                                                                                                                                                    | | ` `[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)                                                            | ` `[getTitle](https://developer.android.com/reference/android/preference/Preference#getTitle())`() ` Returns the title of this Preference.                                                                                                                                                                                                                                                                                                                                                                                                          | | ` int`                                                                                                                                       | ` `[getTitleRes](https://developer.android.com/reference/android/preference/Preference#getTitleRes())`() ` Returns the title resource ID of this Preference.                                                                                                                                                                                                                                                                                                                                                                                        | | ` `[View](https://developer.android.com/reference/android/view/View)                                                                         | ` `[getView](https://developer.android.com/reference/android/preference/Preference#getView(android.view.View,%20android.view.ViewGroup))`(`[View](https://developer.android.com/reference/android/view/View)` convertView, `[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup)` parent) ` Gets the View that will be shown in the [PreferenceActivity](https://developer.android.com/reference/android/preference/PreferenceActivity).                                                                                     | | ` int`                                                                                                                                       | ` `[getWidgetLayoutResource](https://developer.android.com/reference/android/preference/Preference#getWidgetLayoutResource())`() ` Gets the layout resource for the controllable widget portion of this Preference.                                                                                                                                                                                                                                                                                                                                 | | ` boolean`                                                                                                                                   | ` `[hasKey](https://developer.android.com/reference/android/preference/Preference#hasKey())`() ` Checks whether this Preference has a valid key.                                                                                                                                                                                                                                                                                                                                                                                                    | | ` boolean`                                                                                                                                   | ` `[isEnabled](https://developer.android.com/reference/android/preference/Preference#isEnabled())`() ` Checks whether this Preference should be enabled in the list.                                                                                                                                                                                                                                                                                                                                                                                | | ` boolean`                                                                                                                                   | ` `[isIconSpaceReserved](https://developer.android.com/reference/android/preference/Preference#isIconSpaceReserved())`() ` Gets whether the space this preference icon view is reserved.                                                                                                                                                                                                                                                                                                                                                            | | ` boolean`                                                                                                                                   | ` `[isPersistent](https://developer.android.com/reference/android/preference/Preference#isPersistent())`() ` Checks whether this Preference is persistent.                                                                                                                                                                                                                                                                                                                                                                                          | | ` boolean`                                                                                                                                   | ` `[isRecycleEnabled](https://developer.android.com/reference/android/preference/Preference#isRecycleEnabled())`() ` Checks whether this Preference has enabled to have its view recycled when used in the list view.                                                                                                                                                                                                                                                                                                                               | | ` boolean`                                                                                                                                   | ` `[isSelectable](https://developer.android.com/reference/android/preference/Preference#isSelectable())`() ` Checks whether this Preference should be selectable in the list.                                                                                                                                                                                                                                                                                                                                                                       | | ` boolean`                                                                                                                                   | ` `[isSingleLineTitle](https://developer.android.com/reference/android/preference/Preference#isSingleLineTitle())`() ` Gets whether the title of this preference is constrained to a single line.                                                                                                                                                                                                                                                                                                                                                   | | ` void`                                                                                                                                      | ` `[notifyChanged](https://developer.android.com/reference/android/preference/Preference#notifyChanged())`() ` Should be called when the data of this [Preference](https://developer.android.com/reference/android/preference/Preference) has changed.                                                                                                                                                                                                                                                                                              | | ` void`                                                                                                                                      | ` `[notifyDependencyChange](https://developer.android.com/reference/android/preference/Preference#notifyDependencyChange(boolean))`(boolean disableDependents) ` Notifies any listening dependents of a change that affects the dependency.                                                                                                                                                                                                                                                                                                         | | ` void`                                                                                                                                      | ` `[notifyHierarchyChanged](https://developer.android.com/reference/android/preference/Preference#notifyHierarchyChanged())`() ` Should be called when a Preference has been added/removed from this group, or the ordering should be re-evaluated.                                                                                                                                                                                                                                                                                                 | | ` void`                                                                                                                                      | ` `[onAttachedToActivity](https://developer.android.com/reference/android/preference/Preference#onAttachedToActivity())`() ` Called when the Preference hierarchy has been attached to the [PreferenceActivity](https://developer.android.com/reference/android/preference/PreferenceActivity).                                                                                                                                                                                                                                                     | | ` void`                                                                                                                                      | ` `[onAttachedToHierarchy](https://developer.android.com/reference/android/preference/Preference#onAttachedToHierarchy(android.preference.PreferenceManager))`(`[PreferenceManager](https://developer.android.com/reference/android/preference/PreferenceManager)` preferenceManager) ` Called when this Preference has been attached to a Preference hierarchy.                                                                                                                                                                                    | | ` void`                                                                                                                                      | ` `[onBindView](https://developer.android.com/reference/android/preference/Preference#onBindView(android.view.View))`(`[View](https://developer.android.com/reference/android/view/View)` view) ` Binds the created View to the data for this Preference.                                                                                                                                                                                                                                                                                           | | ` void`                                                                                                                                      | ` `[onClick](https://developer.android.com/reference/android/preference/Preference#onClick())`() ` Processes a click on the preference.                                                                                                                                                                                                                                                                                                                                                                                                             | | ` `[View](https://developer.android.com/reference/android/view/View)                                                                         | ` `[onCreateView](https://developer.android.com/reference/android/preference/Preference#onCreateView(android.view.ViewGroup))`(`[ViewGroup](https://developer.android.com/reference/android/view/ViewGroup)` parent) ` Creates the View to be shown for this Preference in the [PreferenceActivity](https://developer.android.com/reference/android/preference/PreferenceActivity).                                                                                                                                                                 | | ` void`                                                                                                                                      | ` `[onDependencyChanged](https://developer.android.com/reference/android/preference/Preference#onDependencyChanged(android.preference.Preference,%20boolean))`(`[Preference](https://developer.android.com/reference/android/preference/Preference)` dependency, boolean disableDependent) ` Called when the dependency changes.                                                                                                                                                                                                                    | | ` `[Object](https://developer.android.com/reference/java/lang/Object)                                                                        | ` `[onGetDefaultValue](https://developer.android.com/reference/android/preference/Preference#onGetDefaultValue(android.content.res.TypedArray,%20int))`(`[TypedArray](https://developer.android.com/reference/android/content/res/TypedArray)` a, int index) ` Called when a Preference is being inflated and the default value attribute needs to be read.                                                                                                                                                                                         | | ` void`                                                                                                                                      | ` `[onParentChanged](https://developer.android.com/reference/android/preference/Preference#onParentChanged(android.preference.Preference,%20boolean))`(`[Preference](https://developer.android.com/reference/android/preference/Preference)` parent, boolean disableChild) ` Called when the implicit parent dependency changes.                                                                                                                                                                                                                    | | ` void`                                                                                                                                      | ` `[onPrepareForRemoval](https://developer.android.com/reference/android/preference/Preference#onPrepareForRemoval())`() ` Called when this Preference is being removed from the hierarchy.                                                                                                                                                                                                                                                                                                                                                         | | ` void`                                                                                                                                      | ` `[onRestoreInstanceState](https://developer.android.com/reference/android/preference/Preference#onRestoreInstanceState(android.os.Parcelable))`(`[Parcelable](https://developer.android.com/reference/android/os/Parcelable)` state) ` Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by [onSaveInstanceState()](https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()).                                                                  | | ` `[Parcelable](https://developer.android.com/reference/android/os/Parcelable)                                                               | ` `[onSaveInstanceState](https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState())`() ` 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.                                                                                                                                                                                                                                                                      | | ` void`                                                                                                                                      | ` `[onSetInitialValue](https://developer.android.com/reference/android/preference/Preference#onSetInitialValue(boolean,%20java.lang.Object))`(boolean restorePersistedValue, `[Object](https://developer.android.com/reference/java/lang/Object)` defaultValue) ` Implement this to set the initial value of the Preference.                                                                                                                                                                                                                        | | ` `[Bundle](https://developer.android.com/reference/android/os/Bundle)                                                                       | ` `[peekExtras](https://developer.android.com/reference/android/preference/Preference#peekExtras())`() ` Return the extras Bundle object associated with this preference, returning `null` if there is not currently one.                                                                                                                                                                                                                                                                                                                           | | ` boolean`                                                                                                                                   | ` `[persistBoolean](https://developer.android.com/reference/android/preference/Preference#persistBoolean(boolean))`(boolean value) ` Attempts to persist a boolean if this Preference is persistent.                                                                                                                                                                                                                                                                                                                                                | | ` boolean`                                                                                                                                   | ` `[persistFloat](https://developer.android.com/reference/android/preference/Preference#persistFloat(float))`(float value) ` Attempts to persist a long if this Preference is persistent.                                                                                                                                                                                                                                                                                                                                                           | | ` boolean`                                                                                                                                   | ` `[persistInt](https://developer.android.com/reference/android/preference/Preference#persistInt(int))`(int value) ` Attempts to persist an int if this Preference is persistent.                                                                                                                                                                                                                                                                                                                                                                   | | ` boolean`                                                                                                                                   | ` `[persistLong](https://developer.android.com/reference/android/preference/Preference#persistLong(long))`(long value) ` Attempts to persist a long if this Preference is persistent.                                                                                                                                                                                                                                                                                                                                                               | | ` boolean`                                                                                                                                   | ` `[persistString](https://developer.android.com/reference/android/preference/Preference#persistString(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` value) ` Attempts to persist a String if this Preference is persistent.                                                                                                                                                                                                                                                                             | | ` boolean`                                                                                                                                   | ` `[persistStringSet](https://developer.android.com/reference/android/preference/Preference#persistStringSet(java.util.Set<java.lang.String>))`(`[Set](https://developer.android.com/reference/java/util/Set)`<`[String](https://developer.android.com/reference/java/lang/String)`> values) ` Attempts to persist a set of Strings if this Preference is persistent.                                                                                                                                                                               | | ` void`                                                                                                                                      | ` `[restoreHierarchyState](https://developer.android.com/reference/android/preference/Preference#restoreHierarchyState(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` container) ` Restore this Preference hierarchy's previously saved state from the given container.                                                                                                                                                                                                                                 | | ` void`                                                                                                                                      | ` `[saveHierarchyState](https://developer.android.com/reference/android/preference/Preference#saveHierarchyState(android.os.Bundle))`(`[Bundle](https://developer.android.com/reference/android/os/Bundle)` container) ` Store this Preference hierarchy's frozen state into the given container.                                                                                                                                                                                                                                                   | | ` void`                                                                                                                                      | ` `[setDefaultValue](https://developer.android.com/reference/android/preference/Preference#setDefaultValue(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` defaultValue) ` Sets the default value for this Preference, which will be set either if persistence is off or persistence is on and the preference is not found in the persistent storage.                                                                                                                                                      | | ` void`                                                                                                                                      | ` `[setDependency](https://developer.android.com/reference/android/preference/Preference#setDependency(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` dependencyKey) ` Sets the key of a Preference that this Preference will depend on.                                                                                                                                                                                                                                                                  | | ` void`                                                                                                                                      | ` `[setEnabled](https://developer.android.com/reference/android/preference/Preference#setEnabled(boolean))`(boolean enabled) ` Sets whether this Preference is enabled.                                                                                                                                                                                                                                                                                                                                                                             | | ` void`                                                                                                                                      | ` `[setFragment](https://developer.android.com/reference/android/preference/Preference#setFragment(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` fragment) ` Sets the class name of a fragment to be shown when this Preference is clicked.                                                                                                                                                                                                                                                              | | ` void`                                                                                                                                      | ` `[setIcon](https://developer.android.com/reference/android/preference/Preference#setIcon(android.graphics.drawable.Drawable))`(`[Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable)` icon) ` Sets the icon for this Preference with a Drawable.                                                                                                                                                                                                                                                                | | ` void`                                                                                                                                      | ` `[setIcon](https://developer.android.com/reference/android/preference/Preference#setIcon(int))`(int iconResId) ` Sets the icon for this Preference with a resource ID.                                                                                                                                                                                                                                                                                                                                                                            | | ` void`                                                                                                                                      | ` `[setIconSpaceReserved](https://developer.android.com/reference/android/preference/Preference#setIconSpaceReserved(boolean))`(boolean iconSpaceReserved) ` Sets whether to reserve the space of this Preference icon view when no icon is provided.                                                                                                                                                                                                                                                                                               | | ` void`                                                                                                                                      | ` `[setIntent](https://developer.android.com/reference/android/preference/Preference#setIntent(android.content.Intent))`(`[Intent](https://developer.android.com/reference/android/content/Intent)` intent) ` Sets an [Intent](https://developer.android.com/reference/android/content/Intent) to be used for [Context.startActivity(Intent)](https://developer.android.com/reference/android/content/Context#startActivity(android.content.Intent)) when this Preference is clicked.                                                               | | ` void`                                                                                                                                      | ` `[setKey](https://developer.android.com/reference/android/preference/Preference#setKey(java.lang.String))`(`[String](https://developer.android.com/reference/java/lang/String)` key) ` Sets the key for this Preference, which is used as a key to the [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences) or [PreferenceDataStore](https://developer.android.com/reference/android/preference/PreferenceDataStore).                                                                                   | | ` void`                                                                                                                                      | ` `[setLayoutResource](https://developer.android.com/reference/android/preference/Preference#setLayoutResource(int))`(int layoutResId) ` Sets the layout resource that is inflated as the [View](https://developer.android.com/reference/android/view/View) to be shown for this Preference.                                                                                                                                                                                                                                                        | | ` void`                                                                                                                                      | ` `[setOnPreferenceChangeListener](https://developer.android.com/reference/android/preference/Preference#setOnPreferenceChangeListener(android.preference.Preference.OnPreferenceChangeListener))`(`[Preference.OnPreferenceChangeListener](https://developer.android.com/reference/android/preference/Preference.OnPreferenceChangeListener)` onPreferenceChangeListener) ` Sets the callback to be invoked when this Preference is changed by the user (but before the internal state has been updated).                                          | | ` void`                                                                                                                                      | ` `[setOnPreferenceClickListener](https://developer.android.com/reference/android/preference/Preference#setOnPreferenceClickListener(android.preference.Preference.OnPreferenceClickListener))`(`[Preference.OnPreferenceClickListener](https://developer.android.com/reference/android/preference/Preference.OnPreferenceClickListener)` onPreferenceClickListener) ` Sets the callback to be invoked when this Preference is clicked.                                                                                                             | | ` void`                                                                                                                                      | ` `[setOrder](https://developer.android.com/reference/android/preference/Preference#setOrder(int))`(int order) ` Sets the order of this Preference with respect to other Preference objects on the same level.                                                                                                                                                                                                                                                                                                                                      | | ` void`                                                                                                                                      | ` `[setPersistent](https://developer.android.com/reference/android/preference/Preference#setPersistent(boolean))`(boolean persistent) ` Sets whether this Preference is persistent.                                                                                                                                                                                                                                                                                                                                                                 | | ` void`                                                                                                                                      | ` `[setPreferenceDataStore](https://developer.android.com/reference/android/preference/Preference#setPreferenceDataStore(android.preference.PreferenceDataStore))`(`[PreferenceDataStore](https://developer.android.com/reference/android/preference/PreferenceDataStore)` dataStore) ` Sets a [PreferenceDataStore](https://developer.android.com/reference/android/preference/PreferenceDataStore) to be used by this Preference instead of using [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences). | | ` void`                                                                                                                                      | ` `[setRecycleEnabled](https://developer.android.com/reference/android/preference/Preference#setRecycleEnabled(boolean))`(boolean enabled) ` Sets whether this Preference has enabled to have its view recycled when used in the list view.                                                                                                                                                                                                                                                                                                         | | ` void`                                                                                                                                      | ` `[setSelectable](https://developer.android.com/reference/android/preference/Preference#setSelectable(boolean))`(boolean selectable) ` Sets whether this Preference is selectable.                                                                                                                                                                                                                                                                                                                                                                 | | ` void`                                                                                                                                      | ` `[setShouldDisableView](https://developer.android.com/reference/android/preference/Preference#setShouldDisableView(boolean))`(boolean shouldDisableView) ` Sets whether this Preference should disable its view when it gets disabled.                                                                                                                                                                                                                                                                                                            | | ` void`                                                                                                                                      | ` `[setSingleLineTitle](https://developer.android.com/reference/android/preference/Preference#setSingleLineTitle(boolean))`(boolean singleLineTitle) ` Sets whether to constrain the title of this Preference to a single line instead of letting it wrap onto multiple lines.                                                                                                                                                                                                                                                                      | | ` void`                                                                                                                                      | ` `[setSummary](https://developer.android.com/reference/android/preference/Preference#setSummary(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` summary) ` Sets the summary for this Preference with a CharSequence.                                                                                                                                                                                                                                                                    | | ` void`                                                                                                                                      | ` `[setSummary](https://developer.android.com/reference/android/preference/Preference#setSummary(int))`(int summaryResId) ` Sets the summary for this Preference with a resource ID.                                                                                                                                                                                                                                                                                                                                                                | | ` void`                                                                                                                                      | ` `[setTitle](https://developer.android.com/reference/android/preference/Preference#setTitle(java.lang.CharSequence))`(`[CharSequence](https://developer.android.com/reference/java/lang/CharSequence)` title) ` Sets the title for this Preference with a CharSequence.                                                                                                                                                                                                                                                                            | | ` void`                                                                                                                                      | ` `[setTitle](https://developer.android.com/reference/android/preference/Preference#setTitle(int))`(int titleResId) ` Sets the title for this Preference with a resource ID.                                                                                                                                                                                                                                                                                                                                                                        | | ` void`                                                                                                                                      | ` `[setWidgetLayoutResource](https://developer.android.com/reference/android/preference/Preference#setWidgetLayoutResource(int))`(int widgetLayoutResId) ` Sets the layout for the controllable widget portion of this Preference.                                                                                                                                                                                                                                                                                                                  | | ` boolean`                                                                                                                                   | ` `[shouldCommit](https://developer.android.com/reference/android/preference/Preference#shouldCommit())`() ` Returns whether the [Preference](https://developer.android.com/reference/android/preference/Preference) should commit its saved value(s) in [getEditor()](https://developer.android.com/reference/android/preference/Preference#getEditor()).                                                                                                                                                                                          | | ` boolean`                                                                                                                                   | ` `[shouldDisableDependents](https://developer.android.com/reference/android/preference/Preference#shouldDisableDependents())`() ` Checks whether this preference's dependents should currently be disabled.                                                                                                                                                                                                                                                                                                                                        | | ` boolean`                                                                                                                                   | ` `[shouldPersist](https://developer.android.com/reference/android/preference/Preference#shouldPersist())`() ` Checks whether, at the given time this method is called, this Preference should store/restore its value(s) into the [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences) or into [PreferenceDataStore](https://developer.android.com/reference/android/preference/PreferenceDataStore) if assigned.                                                                                        | | ` `[String](https://developer.android.com/reference/java/lang/String)                                                                        | ` `[toString](https://developer.android.com/reference/android/preference/Preference#toString())`() ` Returns a string representation of the object.                                                                                                                                                                                                                                                                                                                                                                                                 | ||
| From class ` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                        | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                             | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                            | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this `Object`.                                                                                                                                                 | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                   | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                              | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                           | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                              | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*.                                                                                             | ||
| From interface ` `[java.lang.Comparable](https://developer.android.com/reference/java/lang/Comparable)` ` |-----------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` abstract int` | ` `[compareTo](https://developer.android.com/reference/java/lang/Comparable#compareTo(T))`(`[Preference](https://developer.android.com/reference/android/preference/Preference)` o) ` Compares this object with the specified object for order. | ||

## Public constructors

### TwoStatePreference

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public TwoStatePreference (Context context)
```

<br />

<br />

|         Parameters          ||
|-----------|------------------|
| `context` | `Context` <br /> |

### TwoStatePreference

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public TwoStatePreference (Context context, 
                AttributeSet attrs)
```

<br />

<br />

|            Parameters            ||
|-----------|-----------------------|
| `context` | `Context` <br />      |
| `attrs`   | `AttributeSet` <br /> |

### TwoStatePreference

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public TwoStatePreference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr)
```

<br />

<br />

|              Parameters               ||
|----------------|-----------------------|
| `context`      | `Context` <br />      |
| `attrs`        | `AttributeSet` <br /> |
| `defStyleAttr` | `int` <br />          |

### TwoStatePreference

Added in [API level 21](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public TwoStatePreference (Context context, 
                AttributeSet attrs, 
                int defStyleAttr, 
                int defStyleRes)
```

<br />

<br />

|              Parameters               ||
|----------------|-----------------------|
| `context`      | `Context` <br />      |
| `attrs`        | `AttributeSet` <br /> |
| `defStyleAttr` | `int` <br />          |
| `defStyleRes`  | `int` <br />          |

## Public methods

### getDisableDependentsState

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean getDisableDependentsState ()
```

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

<br />

|                                                             Returns                                                             ||
|-----------|----------------------------------------------------------------------------------------------------------------------|
| `boolean` | Whether dependents are disabled when this preference is on (`true`) or when this preference is off (`false`). <br /> |

### getSummaryOff

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public CharSequence getSummaryOff ()
```

Returns the summary to be shown when unchecked.

<br />

|                                               Returns                                               ||
|--------------------------------------------------------------------------------|---------------------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | The summary. <br /> |

### getSummaryOn

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public CharSequence getSummaryOn ()
```

Returns the summary to be shown when checked.

<br />

|                                               Returns                                               ||
|--------------------------------------------------------------------------------|---------------------|
| [CharSequence](https://developer.android.com/reference/java/lang/CharSequence) | The summary. <br /> |

### isChecked

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean isChecked ()
```

Returns the checked state.

<br />

|               Returns                ||
|-----------|---------------------------|
| `boolean` | The checked state. <br /> |

### setChecked

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setChecked (boolean checked)
```

Sets the checked state and saves it to the [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences).

<br />

|                   Parameters                    ||
|-----------|--------------------------------------|
| `checked` | `boolean`: The checked state. <br /> |

### setDisableDependentsState

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setDisableDependentsState (boolean disableDependentsState)
```

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

<br />

|                                            Parameters                                            ||
|--------------------------|------------------------------------------------------------------------|
| `disableDependentsState` | `boolean`: The preference state that should disable dependents. <br /> |

### setSummaryOff

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setSummaryOff (CharSequence summary)
```

Sets the summary to be shown when unchecked.

<br />

|                                Parameters                                 ||
|-----------|----------------------------------------------------------------|
| `summary` | `CharSequence`: The summary to be shown when unchecked. <br /> |

### setSummaryOff

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setSummaryOff (int summaryResId)
```

<br />

<br />

|                        Parameters                        ||
|----------------|------------------------------------------|
| `summaryResId` | `int`: The summary as a resource. <br /> |

**See also:**

- [setSummaryOff(CharSequence)](https://developer.android.com/reference/android/preference/TwoStatePreference#setSummaryOff(java.lang.CharSequence))  

### setSummaryOn

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setSummaryOn (int summaryResId)
```

<br />

<br />

|                        Parameters                        ||
|----------------|------------------------------------------|
| `summaryResId` | `int`: The summary as a resource. <br /> |

**See also:**

- [setSummaryOn(CharSequence)](https://developer.android.com/reference/android/preference/TwoStatePreference#setSummaryOn(java.lang.CharSequence))  

### setSummaryOn

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public void setSummaryOn (CharSequence summary)
```

Sets the summary to be shown when checked.

<br />

|                               Parameters                                ||
|-----------|--------------------------------------------------------------|
| `summary` | `CharSequence`: The summary to be shown when checked. <br /> |

### shouldDisableDependents

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public boolean shouldDisableDependents ()
```

Checks whether this preference's dependents should currently be
disabled.

<br />

|                                    Returns                                    ||
|-----------|--------------------------------------------------------------------|
| `boolean` | True if the dependents should be disabled, otherwise false. <br /> |

## Protected methods

### onClick

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected void onClick ()
```

Processes a click on the preference. This includes saving the value to
the [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences). However, the overridden method should
call [callChangeListener(java.lang.Object)](https://developer.android.com/reference/android/preference/Preference#callChangeListener(java.lang.Object)) to make sure the client wants to
update the preference's state with the new value.

<br />

### onGetDefaultValue

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected Object onGetDefaultValue (TypedArray a, 
                int index)
```

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)](https://developer.android.com/reference/android/content/res/TypedArray#getString(int)).

<br />

|                            Parameters                            ||
|---------|---------------------------------------------------------|
| `a`     | `TypedArray`: The set of attributes. <br />             |
| `index` | `int`: The index of the default value attribute. <br /> |

|                                                        Returns                                                        ||
|--------------------------------------------------------------------|---------------------------------------------------|
| [Object](https://developer.android.com/reference/java/lang/Object) | The default value of this preference type. <br /> |

### onRestoreInstanceState

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected void onRestoreInstanceState (Parcelable state)
```

Hook allowing a Preference to re-apply a representation of its internal state that had
previously been generated by [onSaveInstanceState()](https://developer.android.com/reference/android/preference/Preference#onSaveInstanceState()). This function will never be called
with a `null` state.

<br />

|                                                                                                    Parameters                                                                                                    ||
|---------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `state` | `Parcelable`: The saved state that had previously been returned by [onSaveInstanceState()](https://developer.android.com/reference/android/preference/TwoStatePreference#onSaveInstanceState()). <br /> |

### onSaveInstanceState

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected Parcelable onSaveInstanceState ()
```

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.

<br />

|                                                                                                                            Returns                                                                                                                             ||
|-----------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| [Parcelable](https://developer.android.com/reference/android/os/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`. <br /> |

### onSetInitialValue

Added in [API level 14](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected void onSetInitialValue (boolean restoreValue, 
                Object defaultValue)
```

Implement this to set the initial value of the Preference.

If <var translate="no">restorePersistedValue</var> is true, you should restore the
Preference value from the [SharedPreferences](https://developer.android.com/reference/android/content/SharedPreferences). If
<var translate="no">restorePersistedValue</var> is false, you should set the Preference
value to defaultValue that is given (and possibly store to SharedPreferences
if [shouldPersist()](https://developer.android.com/reference/android/preference/Preference#shouldPersist()) is true).

In case of using [PreferenceDataStore](https://developer.android.com/reference/android/preference/PreferenceDataStore), the <var translate="no">restorePersistedValue</var> 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.

<br />

|                                                                     Parameters                                                                     ||
|----------------|------------------------------------------------------------------------------------------------------------------------------------|
| `restoreValue` | `boolean`: True to restore the persisted value; false to use the given <var translate="no">defaultValue</var>. <br />              |
| `defaultValue` | `Object`: The default value for this Preference. Only use this if <var translate="no">restorePersistedValue</var> is false. <br /> |