public class EditTextPreference extends DialogPreference
Preference
that allows for string
input.
It is a subclass of DialogPreference
and shows the EditText
in a dialog. This EditText
can be modified either programmatically
via getEditText()
, or through XML by setting any EditText
attributes on the EditTextPreference.
This preference will store a string into the SharedPreferences.
See EditText Attributes
.
Preference.BaseSavedState, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
DEFAULT_ORDER
Constructor and Description |
---|
EditTextPreference(Context context) |
EditTextPreference(Context context,
AttributeSet attrs) |
EditTextPreference(Context context,
AttributeSet attrs,
int defStyle) |
Modifier and Type | Method and Description |
---|---|
EditText |
getEditText()
Returns the
EditText widget that will be shown in the dialog. |
String |
getText()
Gets the text from the
SharedPreferences . |
protected boolean |
needInputMethod()
Returns whether the preference needs to display a soft input method when the dialog
is displayed.
|
protected void |
onAddEditTextToDialogView(View dialogView,
EditText editText)
Adds the EditText widget of this preference to the dialog's view.
|
protected void |
onBindDialogView(View view)
Binds views in the content View of the dialog to data.
|
protected void |
onDialogClosed(boolean positiveResult)
Called when the dialog is dismissed and should be used to save data to
the
SharedPreferences . |
protected Object |
onGetDefaultValue(TypedArray a,
int index)
Called when a Preference is being inflated and the default value
attribute needs to be read.
|
protected void |
onRestoreInstanceState(Parcelable state)
Hook allowing a Preference to re-apply a representation of its internal
state that had previously been generated by
Preference.onSaveInstanceState() . |
protected 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.
|
protected void |
onSetInitialValue(boolean restoreValue,
Object defaultValue)
Implement this to set the initial value of the Preference.
|
void |
setText(String text)
Saves the text to the
SharedPreferences . |
boolean |
shouldDisableDependents()
Checks whether this preference's dependents should currently be
disabled.
|
getDialog, getDialogIcon, getDialogLayoutResource, getDialogMessage, getDialogTitle, getNegativeButtonText, getPositiveButtonText, onActivityDestroy, onClick, onClick, onCreateDialogView, onDismiss, onPrepareDialogBuilder, setDialogIcon, setDialogIcon, setDialogLayoutResource, setDialogMessage, setDialogMessage, setDialogTitle, setDialogTitle, setNegativeButtonText, setNegativeButtonText, setPositiveButtonText, setPositiveButtonText, showDialog
callChangeListener, compareTo, findPreferenceInHierarchy, getContext, getDependency, getEditor, getExtras, getFragment, getIcon, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPersistedStringSet, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getTitleRes, getView, getWidgetLayoutResource, hasKey, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToActivity, onAttachedToHierarchy, onBindView, onCreateView, onDependencyChanged, onKey, onPrepareForRemoval, peekExtras, persistBoolean, persistFloat, persistInt, persistLong, persistString, persistStringSet, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setFragment, setIcon, setIcon, setIntent, setKey, setLayoutResource, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldPersist, toString
public EditTextPreference(Context context, AttributeSet attrs, int defStyle)
public EditTextPreference(Context context, AttributeSet attrs)
public EditTextPreference(Context context)
public void setText(String text)
SharedPreferences
.text
- The text to savepublic String getText()
SharedPreferences
.protected void onBindDialogView(View view)
DialogPreference
Make sure to call through to the superclass implementation.
onBindDialogView
in class DialogPreference
view
- The content View of the dialog, if it is custom.protected void onAddEditTextToDialogView(View dialogView, EditText editText)
dialogView
- The dialog view.protected void onDialogClosed(boolean positiveResult)
DialogPreference
SharedPreferences
.onDialogClosed
in class DialogPreference
positiveResult
- Whether the positive button was clicked (true), or
the negative button was clicked or the dialog was canceled (false).protected Object onGetDefaultValue(TypedArray a, int index)
Preference
For example, if the value type is String, the body of the method would
proxy to TypedArray.getString(int)
.
onGetDefaultValue
in class Preference
a
- The set of attributes.index
- The index of the default value attribute.protected void onSetInitialValue(boolean restoreValue, Object defaultValue)
Preference
If restorePersistedValue is true, you should restore the
Preference value from the SharedPreferences
. If
restorePersistedValue is false, you should set the Preference
value to defaultValue that is given (and possibly store to SharedPreferences
if Preference.shouldPersist()
is true).
This may not always be called. One example is if it should not persist but there is no default value given.
onSetInitialValue
in class Preference
restoreValue
- True to restore the persisted value;
false to use the given defaultValue.defaultValue
- The default value for this Preference. Only use this
if restorePersistedValue is false.public boolean shouldDisableDependents()
Preference
shouldDisableDependents
in class Preference
public EditText getEditText()
EditText
widget that will be shown in the dialog.EditText
widget that will be shown in the dialog.protected boolean needInputMethod()
DialogPreference
needInputMethod
in class DialogPreference
protected Parcelable onSaveInstanceState()
Preference
onSaveInstanceState
in class DialogPreference
Preference.onRestoreInstanceState(android.os.Parcelable)
,
Preference.saveHierarchyState(android.os.Bundle)
protected void onRestoreInstanceState(Parcelable state)
Preference
Preference.onSaveInstanceState()
.
This function will never be called with a null state.onRestoreInstanceState
in class DialogPreference
state
- The saved state that had previously been returned by
Preference.onSaveInstanceState()
.Preference.onSaveInstanceState()
,
Preference.restoreHierarchyState(android.os.Bundle)