Save the date! Android Dev Summit is coming to Sunnyvale, CA on Oct 23-24, 2019.

ListPreference

open class ListPreference : DialogPreference
kotlin.Any
   ↳ androidx.preference.Preference
   ↳ androidx.preference.DialogPreference
   ↳ androidx.preference.ListPreference

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(CharSequence[]) array.

Summary

Nested classes

A simple androidx.preference.Preference.SummaryProvider implementation for a ListPreference.

Inherited constants
Public constructors
<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

<init>(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

<init>(context: Context!, attrs: AttributeSet!)

<init>(context: Context!)

Public methods
open Unit

The array to find the value to save for a preference when an entry from entries is selected.

open Unit
setEntryValues(@ArrayRes entryValuesResId: Int)

open Int

Returns the index of the given value (in the entry values array).

open Unit

Sets the human-readable entries to be shown in the list.

open Unit
setEntries(@ArrayRes entriesResId: Int)

open Array<CharSequence!>!

Returns the array of values to be saved for the preference.

open String!

Returns the value of the key.

open CharSequence!

Returns the entry corresponding to the current value.

open Unit
setValue(value: String!)

Sets the value of the key.

open Unit

Sets the value to the given index from the entry values.

open Unit

open Array<CharSequence!>!

The list of entries to be shown in the list in subsequent dialogs.

open CharSequence!

Protected methods
open Parcelable!

open Unit

open Any!

open Unit
onSetInitialValue(defaultValue: Any?)

Inherited functions

Public constructors

<init>

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

<init>

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

<init>

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

<init>

ListPreference(context: Context!)

Public methods

setEntryValues

open 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

open fun setEntryValues(@ArrayRes entryValuesResId: Int): Unit
Parameters
entryValuesResId Int: The entry values array as a resource

findIndexOfValue

open 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
Return
Int: The index of the value, or -1 if not found

setEntries

open 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(CharSequence[]).

Parameters
entries Array<CharSequence!>!: The entries

setEntries

open fun setEntries(@ArrayRes entriesResId: Int): Unit
Parameters
entriesResId Int: The entries array as a resource

getEntryValues

open fun getEntryValues(): Array<CharSequence!>!

Returns the array of values to be saved for the preference.

Return
Array<CharSequence!>!: The array of values

getValue

open fun getValue(): String!

Returns the value of the key. This should be one of the entries in getEntryValues().

Return
String!: The value of the key

getEntry

open fun getEntry(): CharSequence!

Returns the entry corresponding to the current value.

Return
CharSequence!: The entry corresponding to the current value, or null

setValue

open 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

open 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

setSummary

open fun setSummary(summary: CharSequence!): Unit

getEntries

open fun getEntries(): Array<CharSequence!>!

The list of entries to be shown in the list in subsequent dialogs.

Return
Array<CharSequence!>!: The list as an array

getSummary

open fun getSummary(): CharSequence!

Protected methods

onSaveInstanceState

protected open fun onSaveInstanceState(): Parcelable!

onRestoreInstanceState

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

onGetDefaultValue

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

onSetInitialValue

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