MultiSelectListPreference


public class MultiSelectListPreference extends DialogPreference


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

This preference saves a set of strings. This set will contain one or more mValues from the setEntryValues array.

name android:entries

name android:entryValues

Summary

Public constructors

MultiSelectListPreference(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)
MultiSelectListPreference(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes
)

Public methods

int

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

CharSequence[]

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

CharSequence[]

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

Set<String>

Retrieves the current values of the key.

void
setEntries(CharSequence[] entries)

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

void
setEntries(@ArrayRes int entriesResId)
void
setEntryValues(CharSequence[] entryValues)

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

void
setEntryValues(@ArrayRes int entryValuesResId)
void
setValues(Set<String> values)

Sets the values for the key.

Protected methods

boolean[]
@Nullable Object

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

void

Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by onSaveInstanceState.

@Nullable 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.

void
onSetInitialValue(Object defaultValue)

Implement this to set the initial value of the preference.

Inherited Constants

From androidx.preference.Preference
static final int
DEFAULT_ORDER = 2147483647

Specify for setOrder if a specific order is not required.

Inherited methods

From java.lang.Comparable
abstract int
compareTo(T p)
From androidx.preference.DialogPreference
@Nullable Drawable

Returns the icon to be shown on subsequent dialogs.

int

Returns the layout resource that is used as the content view for subsequent dialogs.

@Nullable CharSequence

Returns the message to be shown on subsequent dialogs.

@Nullable CharSequence

Returns the title to be shown on subsequent dialogs.

@Nullable CharSequence

Returns the text of the negative button to be shown on subsequent dialogs.

@Nullable CharSequence

Returns the text of the positive button to be shown on subsequent dialogs.

void

Processes a click on the preference.

void

Sets the icon of the dialog.

void
setDialogIcon(int dialogIconRes)

Sets the icon (resource ID) of the dialog.

void
setDialogLayoutResource(int dialogLayoutResId)

Sets the layout resource that is inflated as the View to be shown as the content view of subsequent dialogs.

void

Sets the message of the dialog.

void
setDialogMessage(int dialogMessageResId)
void

Sets the title of the dialog.

void
setDialogTitle(int dialogTitleResId)
void

Sets the text of the negative button of the dialog.

void
setNegativeButtonText(int negativeButtonTextResId)
void

Sets the text of the positive button of the dialog.

void
setPositiveButtonText(int positiveButtonTextResId)
From androidx.preference.Preference
boolean

Call this method after the user changes the preference, but before the internal state is set.

int

Compares preference objects based on order (if set), otherwise alphabetically on the titles.

@Nullable T

Finds a preference in the entire hierarchy (above or below this preference) with the given key.

@NonNull Context

Returns the Context of this preference.

@Nullable String

Returns the key of the dependency on this preference.

@NonNull Bundle

Return the extras Bundle object associated with this preference, creating a new Bundle if there currently isn't one.

@Nullable String

Return the fragment class name associated with this preference.

@Nullable Drawable

Returns the icon of this preference.

@Nullable Intent

Return the Intent associated with this preference.

String

Gets the key for this preference, which is also the key used for storing values into SharedPreferences or PreferenceDataStore.

final int

Gets the layout resource that will be shown as the View for this preference.

@Nullable Preference.OnPreferenceChangeListener

Returns the callback to be invoked when this preference is changed by the user (but before the internal state has been updated).

@Nullable Preference.OnPreferenceClickListener

Returns the callback to be invoked when this preference is clicked.

int

Gets the order of this preference with respect to other preference objects on the same level.

@Nullable PreferenceGroup

Returns the 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(boolean defaultReturnValue)

Attempts to get a persisted Boolean if this preference is persistent.

float
getPersistedFloat(float defaultReturnValue)

Attempts to get a persisted Float if this preference is persistent.

int
getPersistedInt(int defaultReturnValue)

Attempts to get a persisted Integer if this preference is persistent.

long
getPersistedLong(long defaultReturnValue)

Attempts to get a persisted Long if this preference is persistent.

String
getPersistedString(String defaultReturnValue)

Attempts to get a persisted set of Strings if this preference is persistent.

Set<String>
getPersistedStringSet(Set<String> defaultReturnValue)

Attempts to get a persisted set of Strings if this preference is persistent.

@Nullable PreferenceDataStore

Returns PreferenceDataStore used by this preference.

PreferenceManager

Gets the PreferenceManager that manages this preference object's tree.

@Nullable SharedPreferences

Returns the SharedPreferences where this preference can read its value(s).

boolean

Checks whether this preference should disable its view when it's action is disabled.

@Nullable CharSequence

Returns the summary of this preference.

final @Nullable Preference.SummaryProvider

Returns the SummaryProvider used to configure the summary of this preference.

@Nullable CharSequence

Returns the title of this preference.

final int

Gets the layout resource for the controllable widget portion of this preference.

boolean

Checks whether this preference has a valid key.

boolean

Returns whether the summary of this preference can be copied to the clipboard by long pressing on the preference.

boolean

Checks whether this preference should be enabled in the list.

boolean

Returns whether the space of this preference icon view is reserved.

boolean

Checks whether this preference is persistent.

boolean

Checks whether this preference should be selectable in the list.

final boolean

Checks whether this preference is shown to the user in the hierarchy.

boolean

Gets whether the title of this preference is constrained to a single line.

final boolean

Checks whether this preference should be visible to the user.

void

Should be called when the data of this Preference has changed.

void
notifyDependencyChange(boolean disableDependents)

Notifies any listening dependents of a change that affects the dependency.

void

Should be called when a preference has been added/removed from this group, or the ordering should be re-evaluated.

void

Called when the preference hierarchy has been attached to the list of preferences.

void

Called when this preference has been attached to a preference hierarchy.

void

Binds the created View to the data for this preference.

void
onDependencyChanged(
    @NonNull Preference dependency,
    boolean disableDependent
)

Called when the dependency changes.

void

Called when the preference hierarchy has been detached from the list of preferences.

void

This method is deprecated.

Preferences aren't views.

void
onParentChanged(@NonNull Preference parent, boolean disableChild)

Called when the implicit parent dependency changes.

void

Called when this preference is being removed from the hierarchy.

void
onSetInitialValue(boolean restorePersistedValue, Object defaultValue)

This method is deprecated.

Use onSetInitialValue instead.

@Nullable Bundle

Return the extras Bundle object associated with this preference, returning null if there is not currently one.

boolean
persistBoolean(boolean value)

Attempts to persist a Boolean if this preference is persistent.

boolean
persistFloat(float value)

Attempts to persist a Float if this preference is persistent.

boolean
persistInt(int value)

Attempts to persist an Integer if this preference is persistent.

boolean
persistLong(long value)

Attempts to persist a Long if this preference is persistent.

boolean

Attempts to persist a String if this preference is persistent.

boolean

Attempts to persist a set of Strings if this preference is persistent.

void

Restore this preference hierarchy's previously saved state from the given container.

void

Store this preference hierarchy's frozen state into the given container.

void
setCopyingEnabled(boolean enabled)

Sets whether the summary of this preference can be copied to the clipboard by long pressing on the preference.

void
setDefaultValue(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(@Nullable String dependencyKey)

Sets the key of a preference that this preference will depend on.

void
setEnabled(boolean enabled)

Sets whether this preference is enabled.

void

Sets the class name of a fragment to be shown when this preference is clicked.

void

Sets the icon for this preference with a Drawable.

void
setIcon(int iconResId)

Sets the icon for this preference with a resource ID.

void
setIconSpaceReserved(boolean iconSpaceReserved)

Sets whether to reserve the space of this preference icon view when no icon is provided.

void

Sets an Intent to be used for startActivity when this preference is clicked.

void

Sets the key for this preference, which is used as a key to the SharedPreferences or PreferenceDataStore.

void
setLayoutResource(int layoutResId)

Sets the layout resource that is inflated as the View to be shown for this preference.

void

Sets the callback to be invoked when this preference is changed by the user (but before the internal state has been updated).

void

Sets the callback to be invoked when this preference is clicked.

void
setOrder(int order)

Sets the order of this preference with respect to other preference objects on the same level.

void
setPersistent(boolean persistent)

Sets whether this preference is persistent.

void

Sets a PreferenceDataStore to be used by this preference instead of using SharedPreferences.

void
setSelectable(boolean selectable)

Sets whether this preference is selectable.

void
setShouldDisableView(boolean shouldDisableView)

Sets whether this preference should disable its view when it gets disabled.

void
setSingleLineTitle(boolean singleLineTitle)

Sets whether to constrain the title of this preference to a single line instead of letting it wrap onto multiple lines.

void

Sets the summary for this preference with a CharSequence.

void
setSummary(int summaryResId)

Sets the summary for this preference with a resource ID.

final void

Set a SummaryProvider that will be invoked whenever the summary of this preference is requested.

void

Sets the title for this preference with a CharSequence.

void
setTitle(int titleResId)

Sets the title for this preference with a resource ID.

void
setViewId(int viewId)

Set the ID that will be assigned to the overall View representing this preference, once bound.

final void
setVisible(boolean visible)

Sets whether this preference should be visible to the user.

void
setWidgetLayoutResource(int widgetLayoutResId)

Sets the layout for the controllable widget portion of this preference.

boolean

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

boolean

Checks whether, at the given time this method is called, this preference should store/restore its value(s) into the SharedPreferences or into PreferenceDataStore if assigned.

@NonNull String

Public constructors

MultiSelectListPreference

Added in 1.0.0
public MultiSelectListPreference(@NonNull Context context)

MultiSelectListPreference

Added in 1.0.0
public MultiSelectListPreference(
    @NonNull Context context,
    @Nullable AttributeSet attrs
)

MultiSelectListPreference

Added in 1.0.0
public MultiSelectListPreference(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr
)

MultiSelectListPreference

Added in 1.0.0
public MultiSelectListPreference(
    @NonNull Context context,
    @Nullable AttributeSet attrs,
    int defStyleAttr,
    int defStyleRes
)

Public methods

findIndexOfValue

Added in 1.0.0
public int findIndexOfValue(String value)

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

Parameters
String value

The value whose index should be returned

Returns
int

The index of the value, or -1 if not found

getEntries

Added in 1.0.0
public CharSequence[] getEntries()

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

Returns
CharSequence[]

The list as an array

getEntryValues

Added in 1.0.0
public CharSequence[] getEntryValues()

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

Returns
CharSequence[]

The array of mValues

getValues

Added in 1.0.0
public Set<StringgetValues()

Retrieves the current values of the key.

Returns
Set<String>

The set of current values

setEntries

Added in 1.0.0
public void setEntries(CharSequence[] entries)

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
CharSequence[] entries

The entries

See also
setEntryValues

setEntries

Added in 1.0.0
public void setEntries(@ArrayRes int entriesResId)
Parameters
@ArrayRes int entriesResId

The entries array as a resource

See also
setEntries

setEntryValues

Added in 1.0.0
public void setEntryValues(CharSequence[] entryValues)

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
CharSequence[] entryValues

The array to be used as mValues to save for the preference

setEntryValues

Added in 1.0.0
public void setEntryValues(@ArrayRes int entryValuesResId)
Parameters
@ArrayRes int entryValuesResId

The entry mValues array as a resource

See also
setEntryValues

setValues

Added in 1.0.0
public void setValues(Set<String> values)

Sets the values for the key. This should contain entries in getEntryValues.

Parameters
Set<String> values

The mValues to set for the key

Protected methods

getSelectedItems

Added in 1.0.0
protected boolean[] getSelectedItems()

onGetDefaultValue

protected @Nullable Object onGetDefaultValue(@NonNull 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 getString.

Parameters
@NonNull TypedArray a

The set of attributes

int index

The index of the default value attribute

Returns
@Nullable Object

The default value of this preference type

onRestoreInstanceState

protected void onRestoreInstanceState(@Nullable Parcelable state)

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
@Nullable Parcelable state

The saved state that had previously been returned by onSaveInstanceState.

onSaveInstanceState

protected @Nullable 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.

Returns
@Nullable 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 void onSetInitialValue(Object defaultValue)

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
Object defaultValue

The default value for the preference if set, otherwise null.