DropDownPreference
public class DropDownPreference extends ListPreference
| java.lang.Object | ||||
| ↳ | androidx.preference.Preference | |||
| ↳ | androidx.preference.DialogPreference | |||
| ↳ | androidx.preference.ListPreference | |||
| ↳ | androidx.preference.DropDownPreference |
A ListPreference that presents the options in a drop down menu rather than a dialog.
Summary
Public constructors |
|---|
DropDownPreference(@NonNull Context context) |
DropDownPreference(@NonNull Context context, @Nullable AttributeSet attrs) |
DropDownPreference( |
DropDownPreference( |
Public methods |
|
|---|---|
void |
onBindViewHolder(@NonNull PreferenceViewHolder holder)Binds the created View to the data for this preference. |
void |
setEntries(@NonNull CharSequence[] entries)Sets the human-readable entries to be shown in the list. |
void |
setValueIndex(int index)Sets the value to the given index from the entry values. |
Protected methods |
|
|---|---|
@NonNull ArrayAdapter |
By default, this class uses a simple |
void |
Should be called when the data of this |
void |
onClick()Processes a click on the preference. |
Inherited Constants |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
DropDownPreference
public DropDownPreference(@NonNull Context context, @Nullable AttributeSet attrs)
DropDownPreference
public DropDownPreference(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyle
)
DropDownPreference
public DropDownPreference(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
int defStyleRes
)
Public methods
onBindViewHolder
public void onBindViewHolder(@NonNull PreferenceViewHolder holder)
Binds the created View to the data for this preference.
This is a good place to grab references to custom Views in the layout and set properties on them.
Make sure to call through to the superclass's implementation.
| Parameters | |
|---|---|
@NonNull PreferenceViewHolder holder |
The ViewHolder that provides references to the views to fill in. These views will be recycled, so you should not hold a reference to them after this method returns. |
setEntries
public void setEntries(@NonNull 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 | |
|---|---|
@NonNull CharSequence[] entries |
The entries |
| See also | |
|---|---|
setEntryValues |
setValueIndex
public void setValueIndex(int index)
Sets the value to the given index from the entry values.
| Parameters | |
|---|---|
int index |
The index of the value to set |
Protected methods
createAdapter
protected @NonNull ArrayAdapter createAdapter()
By default, this class uses a simple ArrayAdapter. But if you need a more complicated adapter, this method can be overridden to create a custom one.
Note: This method is called from the constructor. Overridden methods will get called before any subclass initialization.
| Returns | |
|---|---|
@NonNull ArrayAdapter |
The custom |
notifyChanged
protected void notifyChanged()
Should be called when the data of this Preference has changed.
onClick
protected void onClick()
Processes a click on the preference. This includes saving the value to the SharedPreferences. However, the overridden method should call callChangeListener to make sure the client wants to update the preference's state with the new value.