Added in API level 11
Deprecated in API level 29

MultiSelectListPreference


open class MultiSelectListPreference : DialogPreference
kotlin.Any
   ↳ android.preference.Preference
   ↳ android.preference.DialogPreference
   ↳ android.preference.MultiSelectListPreference

A Preference that displays a list of entries as a dialog.

This preference will store a set of strings into the SharedPreferences. This set will contain one or more values 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

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

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

Public methods
open Int

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 Array<CharSequence!>!

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

open MutableSet<String!>!

Retrieves the current value of the key.

open Unit
setEntries(entriesResId: Int)

open Unit

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

open Unit
setEntryValues(entryValuesResId: Int)

open Unit

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

open Unit

Sets the value of the key.

Protected methods
open Unit
onDialogClosed(positiveResult: Boolean)

Called when the dialog is dismissed and should be used to save data to the SharedPreferences.

open Any!

Called when a Preference is being inflated and the default value attribute needs to be read.

open Unit

Prepares the dialog builder to be shown when the preference is clicked.

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:entries
The human-readable array to present as a list. Each entry must have a corresponding index in entryValues.

May 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:entryValues
The array to find the value to save for a preference when an entry from entries is selected. If a user clicks the second item in entries, the second item in this array will be saved to the preference.

May be a reference to another resource, in the form "@[+][package:]type/name" or a theme attribute in the form "?[package:]type/name".

Public constructors

MultiSelectListPreference

Added in API level 11
MultiSelectListPreference(context: Context!)

MultiSelectListPreference

Added in API level 11
MultiSelectListPreference(
    context: Context!,
    attrs: AttributeSet!)

MultiSelectListPreference

Added in API level 21
MultiSelectListPreference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

MultiSelectListPreference

Added in API level 21
MultiSelectListPreference(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

findIndexOfValue

Added in API level 11
open fun findIndexOfValue(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

Added in API level 11
open fun getEntries(): 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.

getEntryValues

Added in API level 11
open fun getEntryValues(): Array<CharSequence!>!

Deprecated: Deprecated in Java.

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

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

getValues

Added in API level 11
open fun getValues(): MutableSet<String!>!

Deprecated: Deprecated in Java.

Retrieves the current value of the key.

setEntries

Added in API level 11
open fun setEntries(entriesResId: Int): Unit

Deprecated: Deprecated in Java.

Parameters
entriesResId Int: The entries array as a resource.

setEntries

Added in API level 11
open fun setEntries(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.

setEntryValues

Added in API level 11
open fun setEntryValues(entryValuesResId: Int): Unit

Deprecated: Deprecated in Java.

Parameters
entryValuesResId Int: The entry values array as a resource.

setEntryValues

Added in API level 11
open fun setEntryValues(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.

setValues

Added in API level 11
open fun setValues(values: MutableSet<String!>!): Unit

Deprecated: Deprecated in Java.

Sets the value of the key. This should contain entries in getEntryValues().

Parameters
values MutableSet<String!>!: The values to set for the key.

Protected methods

onDialogClosed

Added in API level 11
protected open fun onDialogClosed(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

Added in API level 11
protected open fun onGetDefaultValue(
    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

Added in API level 11
protected open fun onPrepareDialogBuilder(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().

onSaveInstanceState

Added in API level 11
protected open fun onSaveInstanceState(): 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

Added in API level 11
protected open fun onSetInitialValue(
    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.