ListPreference
class ListPreference : DialogPreference
| kotlin.Any | |||
| ↳ | androidx.preference.Preference | ||
| ↳ | androidx.preference.DialogPreference | ||
| ↳ | androidx.preference.ListPreference |
DropDownPreference |
A |
A Preference that displays a list of entries as a dialog.
This preference saves a string value. This string will be the value from the setEntryValues array.
name android:entries
name android:entryValues
Summary
Nested types |
|---|
|
A simple |
Public constructors |
|---|
ListPreference(context: Context) |
ListPreference(context: Context, attrs: AttributeSet?) |
ListPreference(context: Context, attrs: AttributeSet?, defStyleAttr: Int) |
ListPreference( |
Public functions |
|
|---|---|
Int |
findIndexOfValue(value: String!)Returns the index of the given value (in the entry values array). |
Array<CharSequence!>! |
The list of entries to be shown in the list in subsequent dialogs. |
CharSequence? |
getEntry()Returns the entry corresponding to the current value. |
Array<CharSequence!>! |
Returns the array of values to be saved for the preference. |
CharSequence? |
Returns the summary of this preference. |
String! |
getValue()Returns the value of the key. |
Unit |
setEntries(entries: Array<CharSequence!>!)Sets the human-readable entries to be shown in the list. |
Unit |
setEntries(entriesResId: @ArrayRes Int) |
Unit |
setEntryValues(entryValues: Array<CharSequence!>!)The array to find the value to save for a preference when an entry from entries is selected. |
Unit |
setEntryValues(entryValuesResId: @ArrayRes Int) |
Unit |
setSummary(summary: CharSequence?)Sets the summary for this preference with a CharSequence. |
Unit |
Sets the value of the key. |
Unit |
setValueIndex(index: Int)Sets the value to the given index from the entry values. |
Protected functions |
|
|---|---|
Any! |
onGetDefaultValue(a: TypedArray, index: Int)Called when a preference is being inflated and the default value attribute needs to be read. |
Unit |
onRestoreInstanceState(state: Parcelable?)Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by |
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. |
Unit |
onSetInitialValue(defaultValue: Any!)Implement this to set the initial value of the preference. |
Inherited Constants |
||
|---|---|---|
|
Inherited functions |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
ListPreference
ListPreference(context: Context, attrs: AttributeSet?, defStyleAttr: Int)
ListPreference
ListPreference(
context: Context,
attrs: AttributeSet?,
defStyleAttr: Int,
defStyleRes: Int
)
Public functions
findIndexOfValue
fun findIndexOfValue(value: String!): Int
Returns the index of the given value (in the entry values array).
| Parameters | |
|---|---|
value: String! |
The value whose index should be returned |
| Returns | |
|---|---|
Int |
The index of the value, or -1 if not found |
getEntries
fun getEntries(): Array<CharSequence!>!
The list of entries to be shown in the list in subsequent dialogs.
| Returns | |
|---|---|
Array<CharSequence!>! |
The list as an array |
getEntry
fun getEntry(): CharSequence?
Returns the entry corresponding to the current value.
| Returns | |
|---|---|
CharSequence? |
The entry corresponding to the current value, or |
getEntryValues
fun getEntryValues(): Array<CharSequence!>!
Returns the array of values to be saved for the preference.
| Returns | |
|---|---|
Array<CharSequence!>! |
The array of values |
getSummary
fun getSummary(): CharSequence?
Returns the summary of this preference. If a SummaryProvider has been set for this preference, it will be used to provide the summary returned by this method.
| Returns | |
|---|---|
CharSequence? |
The summary |
| See also | |
|---|---|
setSummary |
|
setSummaryProvider |
getValue
fun getValue(): String!
Returns the value of the key. This should be one of the entries in getEntryValues.
| Returns | |
|---|---|
String! |
The value of the key |
setEntries
fun setEntries(entries: Array<CharSequence!>!): Unit
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.
| Parameters | |
|---|---|
entries: Array<CharSequence!>! |
The entries |
| See also | |
|---|---|
setEntryValues |
setEntryValues
fun setEntryValues(entryValues: Array<CharSequence!>!): Unit
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 |
setEntryValues
fun setEntryValues(entryValuesResId: @ArrayRes Int): Unit
| See also | |
|---|---|
setEntryValues |
setSummary
fun setSummary(summary: CharSequence?): Unit
Sets the summary for this preference with a CharSequence.
You can also use a SummaryProvider to dynamically configure the summary of this preference.
| Parameters | |
|---|---|
summary: CharSequence? |
The summary for the preference |
| Throws | |
|---|---|
java.lang.IllegalStateException |
If a |
| See also | |
|---|---|
setSummaryProvider |
setValue
fun setValue(value: String!): Unit
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
fun setValueIndex(index: Int): Unit
Sets the value to the given index from the entry values.
| Parameters | |
|---|---|
index: Int |
The index of the value to set |
Protected functions
onGetDefaultValue
protected fun onGetDefaultValue(a: TypedArray, index: Int): Any!
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 getString.
| Parameters | |
|---|---|
a: TypedArray |
The set of attributes |
index: Int |
The index of the default value attribute |
| Returns | |
|---|---|
Any! |
The default value of this preference type |
onRestoreInstanceState
protected fun onRestoreInstanceState(state: Parcelable?): Unit
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 |
| See also | |
|---|---|
onSaveInstanceState |
|
restoreHierarchyState |
onSaveInstanceState
protected fun onSaveInstanceState(): 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. This state should only contain information that is not persistent or can be reconstructed later.
| Returns | |
|---|---|
Parcelable? |
A Parcelable object containing the current dynamic state of this preference, or |
| See also | |
|---|---|
onRestoreInstanceState |
|
saveHierarchyState |
onSetInitialValue
protected fun onSetInitialValue(defaultValue: Any!): Unit
Implement this to set the initial value of the preference.
If you are persisting values to SharedPreferences or a PreferenceDataStore you should restore the saved value for the preference.
If you are not persisting values, or there is no value saved for the preference, you should set the value of the preference to defaultValue.
| Parameters | |
|---|---|
defaultValue: Any! |
The default value for the preference if set, otherwise |