EditTextPreference
public class EditTextPreference extends DialogPreference
| java.lang.Object | |||
| ↳ | androidx.preference.Preference | ||
| ↳ | androidx.preference.DialogPreference | ||
| ↳ | androidx.preference.EditTextPreference |
A DialogPreference that shows a EditText in the dialog.
This preference saves a string value.
Summary
Nested types |
|---|
public interface EditTextPreference.OnBindEditTextListenerInterface definition for a callback to be invoked when the corresponding dialog view for this preference is bound. |
public final class EditTextPreference.SimpleSummaryProvider implements Preference.SummaryProviderA simple |
Public constructors |
|---|
EditTextPreference(@NonNull Context context) |
EditTextPreference(@NonNull Context context, @Nullable AttributeSet attrs) |
EditTextPreference( |
EditTextPreference( |
Public methods |
|
|---|---|
@Nullable String |
getText()Gets the text from the current data storage. |
void |
setOnBindEditTextListener(Set an |
void |
Saves the text to the current data storage. |
boolean |
Checks whether this preference's dependents should currently be disabled. |
Protected methods |
|
|---|---|
Object |
onGetDefaultValue(@NonNull TypedArray a, int index)Called when a preference is being inflated and the default value attribute needs to be read. |
void |
onRestoreInstanceState(@Nullable Parcelable state)Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by |
@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 |
||
|---|---|---|
|
Inherited methods |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Public constructors
EditTextPreference
public EditTextPreference(@NonNull Context context, @Nullable AttributeSet attrs)
EditTextPreference
public EditTextPreference(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr
)
EditTextPreference
public EditTextPreference(
@NonNull Context context,
@Nullable AttributeSet attrs,
int defStyleAttr,
int defStyleRes
)
Public methods
getText
public @Nullable String getText()
Gets the text from the current data storage.
setOnBindEditTextListener
public void setOnBindEditTextListener(
@Nullable EditTextPreference.OnBindEditTextListener onBindEditTextListener
)
Set an OnBindEditTextListener that will be invoked when the corresponding dialog view for this preference is bound. Set null to remove the existing OnBindEditTextListener.
| Parameters | |
|---|---|
@Nullable EditTextPreference.OnBindEditTextListener onBindEditTextListener |
The |
setText
public void setText(@Nullable String text)
Saves the text to the current data storage.
shouldDisableDependents
public boolean shouldDisableDependents()
Checks whether this preference's dependents should currently be disabled.
| Returns | |
|---|---|
boolean |
|
Protected methods
onGetDefaultValue
protected 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 | |
|---|---|
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 |
| See also | |
|---|---|
onSaveInstanceState |
|
restoreHierarchyState |
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 |
| See also | |
|---|---|
onRestoreInstanceState |
|
saveHierarchyState |
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 |