ListPreference
open classListPreference: DialogPreference
| kotlin.Any | |||
| ↳ | android.preference.Preference | ||
| ↳ | android.preference.DialogPreference | ||
| ↳ | android.preference.ListPreference | ||
A Preference that displays a list of entries as a dialog.
This preference will store a string into the SharedPreferences. This string will be the value from the setEntryValues(java.lang.CharSequence[]) array.
Summary
| XML attributes | |
|---|---|
android:entries |
The human-readable array to present as a list. |
android:entryValues |
The array to find the value to save for a preference when an entry from entries is selected. |
| Inherited XML attributes | |
|---|---|
| Inherited constants | |
|---|---|
| Public constructors | |
|---|---|
ListPreference(context: Context!) |
|
ListPreference(context: Context!, attrs: AttributeSet!) |
|
ListPreference(context: Context!, attrs: AttributeSet!, defStyleAttr: Int) |
|
ListPreference(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int) |
|
| Public methods | |
|---|---|
| open Int |
findIndexOfValue(value: String!)Returns the index of the given value (in the entry values array). |
| open Array<CharSequence!>! |
The list of entries to be shown in the list in subsequent dialogs. |
| open CharSequence! |
getEntry()Returns the entry corresponding to the current value. |
| open Array<CharSequence!>! |
Returns the array of values to be saved for the preference. |
| open CharSequence! |
Returns the summary of this ListPreference. |
| open String! |
getValue()Returns the value of the key. |
| open Unit |
setEntries(entriesResId: Int) |
| open Unit |
setEntries(entries: Array<CharSequence!>!)Sets the human-readable entries to be shown in the list. |
| open Unit |
setEntryValues(entryValuesResId: Int) |
| open Unit |
setEntryValues(entryValues: Array<CharSequence!>!)The array to find the value to save for a preference when an entry from entries is selected. |
| open Unit |
setSummary(summary: CharSequence!)Sets the summary for this Preference with a CharSequence. |
| open Unit |
Sets the value of the key. |
| open Unit |
setValueIndex(index: Int)Sets the value to the given index from the entry values. |
| Protected methods | |
|---|---|
| open Unit |
onDialogClosed(positiveResult: Boolean)Called when the dialog is dismissed and should be used to save data to the |
| open Any! |
onGetDefaultValue(a: TypedArray!, index: Int)Called when a Preference is being inflated and the default value attribute needs to be read. |
| open Unit |
onPrepareDialogBuilder(builder: AlertDialog.Builder!)Prepares the dialog builder to be shown when the preference is clicked. |
| open Unit |
onRestoreInstanceState(state: Parcelable!)Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by |
| open Parcelable! |
Hook allowing a Preference to generate a representation of its internal state that can later be used to create a new instance with that same state. |
| open Unit |
onSetInitialValue(restoreValue: Boolean, defaultValue: Any!)Implement this to set the initial value of the Preference. |
| Inherited functions | |
|---|---|
XML attributes
android:entries
android:entriesMay be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".
android:entryValues
android:entryValuesMay be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".
Public constructors
ListPreference
ListPreference(
context: Context!,
attrs: AttributeSet!,
defStyleAttr: Int)
ListPreference
ListPreference(
context: Context!,
attrs: AttributeSet!,
defStyleAttr: Int,
defStyleRes: Int)
Public methods
findIndexOfValue
open funfindIndexOfValue(value: String!): Int
Deprecated: Deprecated in Java.
Returns the index of the given value (in the entry values array).
| Parameters | |
|---|---|
value |
String!: The value whose index should be returned. |
| Return | |
|---|---|
Int |
The index of the value, or -1 if not found. |
getEntries
open fungetEntries(): Array<CharSequence!>!
Deprecated: Deprecated in Java.
The list of entries to be shown in the list in subsequent dialogs.
| Return | |
|---|---|
Array<CharSequence!>! |
The list as an array. |
getEntry
open fungetEntry(): CharSequence!
Deprecated: Deprecated in Java.
Returns the entry corresponding to the current value.
| Return | |
|---|---|
CharSequence! |
The entry corresponding to the current value, or null. |
getEntryValues
open fungetEntryValues(): Array<CharSequence!>!
Deprecated: Deprecated in Java.
Returns the array of values to be saved for the preference.
| Return | |
|---|---|
Array<CharSequence!>! |
The array of values. |
getSummary
open fungetSummary(): CharSequence!
Deprecated: Deprecated in Java.
Returns the summary of this ListPreference. If the summary has a java.lang.String#format marker in it (i.e. "%s" or "%1$s"), then the current entry value will be substituted in its place.
| Return | |
|---|---|
CharSequence! |
the summary with appropriate string substitution |
getValue
open fungetValue(): String!
Deprecated: Deprecated in Java.
Returns the value of the key. This should be one of the entries in getEntryValues().
| Return | |
|---|---|
String! |
The value of the key. |
setEntries
open funsetEntries(entriesResId: Int): Unit
Deprecated: Deprecated in Java.
| Parameters | |
|---|---|
entriesResId |
Int: The entries array as a resource. |
See Also
setEntries
open funsetEntries(entries: Array<CharSequence!>!): Unit
Deprecated: Deprecated in Java.
Sets the human-readable entries to be shown in the list. This will be shown in subsequent dialogs.
Each entry must have a corresponding index in setEntryValues(java.lang.CharSequence[]).
| Parameters | |
|---|---|
entries |
Array<CharSequence!>!: The entries. |
See Also
setEntryValues
open funsetEntryValues(entryValuesResId: Int): Unit
Deprecated: Deprecated in Java.
| Parameters | |
|---|---|
entryValuesResId |
Int: The entry values array as a resource. |
See Also
setEntryValues
open funsetEntryValues(entryValues: Array<CharSequence!>!): Unit
Deprecated: Deprecated in Java.
The array to find the value to save for a preference when an entry from entries is selected. If a user clicks on the second item in entries, the second item in this array will be saved to the preference.
| Parameters | |
|---|---|
entryValues |
Array<CharSequence!>!: The array to be used as values to save for the preference. |
setSummary
open funsetSummary(summary: CharSequence!): Unit
Deprecated: Deprecated in Java.
Sets the summary for this Preference with a CharSequence. If the summary has a java.lang.String#format marker in it (i.e. "%s" or "%1$s"), then the current entry value will be substituted in its place when it's retrieved.
| Parameters | |
|---|---|
summary |
CharSequence!: The summary for the preference. |
setValue
open funsetValue(value: String!): Unit
Deprecated: Deprecated in Java.
Sets the value of the key. This should be one of the entries in getEntryValues().
| Parameters | |
|---|---|
value |
String!: The value to set for the key. |
setValueIndex
open funsetValueIndex(index: Int): Unit
Deprecated: Deprecated in Java.
Sets the value to the given index from the entry values.
| Parameters | |
|---|---|
index |
Int: The index of the value to set. |
Protected methods
onDialogClosed
protected open funonDialogClosed(positiveResult: Boolean): Unit
Deprecated: Deprecated in Java.
Called when the dialog is dismissed and should be used to save data to the SharedPreferences.
| Parameters | |
|---|---|
positiveResult |
Boolean: Whether the positive button was clicked (true), or the negative button was clicked or the dialog was canceled (false). |
onGetDefaultValue
protected open funonGetDefaultValue(
a: TypedArray!,
index: Int
): Any!
Deprecated: Deprecated in Java.
Called when a Preference is being inflated and the default value attribute needs to be read. Since different Preference types have different value types, the subclass should get and return the default value which will be its value type.
For example, if the value type is String, the body of the method would proxy to TypedArray.getString(int).
| Parameters | |
|---|---|
a |
TypedArray!: The set of attributes. |
index |
Int: The index of the default value attribute. |
| Return | |
|---|---|
Any! |
The default value of this preference type. |
onPrepareDialogBuilder
protected open funonPrepareDialogBuilder(builder: AlertDialog.Builder!): Unit
Deprecated: Deprecated in Java.
Prepares the dialog builder to be shown when the preference is clicked. Use this to set custom properties on the dialog.
Do not AlertDialog.Builder.create() or AlertDialog.Builder.show().
onRestoreInstanceState
protected open funonRestoreInstanceState(state: Parcelable!): Unit
Deprecated: Deprecated in Java.
Hook allowing a Preference to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState. This function will never be called with a null state.
| Parameters | |
|---|---|
state |
Parcelable!: The saved state that had previously been returned by onSaveInstanceState. |
onSaveInstanceState
protected open funonSaveInstanceState(): Parcelable!
Deprecated: Deprecated in Java.
Hook allowing a Preference to generate a representation of its internal state that can later be used to create a new instance with that same state. This state should only contain information that is not persistent or can be reconstructed later.
| Return | |
|---|---|
Parcelable! |
A Parcelable object containing the current dynamic state of this Preference, or null if there is nothing interesting to save. The default implementation returns null. |
onSetInitialValue
protected open funonSetInitialValue(
restoreValue: Boolean,
defaultValue: Any!
): Unit
Deprecated: Deprecated in Java.
Implement this to set the initial value of the Preference.
If restorePersistedValue is true, you should restore the Preference value from the android.content.SharedPreferences. If restorePersistedValue is false, you should set the Preference value to defaultValue that is given (and possibly store to SharedPreferences if shouldPersist() is true).
In case of using PreferenceDataStore, the restorePersistedValue is always true. But the default value (if provided) is set.
This may not always be called. One example is if it should not persist but there is no default value given.
| Parameters | |
|---|---|
restorePersistedValue |
True to restore the persisted value; false to use the given defaultValue. |
defaultValue |
Any!: The default value for this Preference. Only use this if restorePersistedValue is false. |