Build 1.0_r1(from source)

android.preference
Class EditTextPreference

java.lang.Object
  extended by android.preference.Preference
      extended by android.preference.DialogPreference
          extended by android.preference.EditTextPreference
All Implemented Interfaces:
DialogInterface.OnClickListener, DialogInterface.OnDismissListener, OnDependencyChangeListener, PreferenceManager.OnActivityDestroyListener, Comparable<Preference>

public class EditTextPreference
extends DialogPreference

The EditTextPreference class is a 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.


Nested Class Summary
 
Nested classes/interfaces inherited from class android.preference.Preference
Preference.BaseSavedState, Preference.OnPreferenceChangeInternalListener, Preference.OnPreferenceChangeListener, Preference.OnPreferenceClickListener
 
Field Summary
 
Fields inherited from class android.preference.Preference
DEFAULT_ORDER
 
Constructor Summary
EditTextPreference(Context context)
           
EditTextPreference(Context context, AttributeSet attrs)
           
EditTextPreference(Context context, AttributeSet attrs, int defStyle)
           
 
Method Summary
 EditText getEditText()
          Returns the EditText widget that will be shown in the dialog.
 String getText()
          Gets the text from the SharedPreferences.
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 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()
          Should return whether this preference's dependents should currently be disabled.
 
Methods inherited from class android.preference.DialogPreference
getDialogIcon, getDialogLayoutResource, getDialogMessage, getDialogTitle, getNegativeButtonText, getPositiveButtonText, onActivityDestroy, onClick, onClick, onCreateDialogView, onDismiss, onPrepareDialogBuilder, setDialogIcon, setDialogIcon, setDialogLayoutResource, setDialogMessage, setDialogMessage, setDialogTitle, setDialogTitle, setNegativeButtonText, setNegativeButtonText, setPositiveButtonText, setPositiveButtonText, showDialog
 
Methods inherited from class android.preference.Preference
callChangeListener, compareTo, dispatchRestoreInstanceState, dispatchSaveInstanceState, findPreferenceInHierarchy, getContext, getDependency, getEditor, getFilterableStringBuilder, getId, getIntent, getKey, getLayoutResource, getOnPreferenceChangeListener, getOnPreferenceClickListener, getOrder, getPersistedBoolean, getPersistedFloat, getPersistedInt, getPersistedLong, getPersistedString, getPreferenceManager, getSharedPreferences, getShouldDisableView, getSummary, getTitle, getView, getWidgetLayoutResource, hasKey, hasSpecifiedLayout, isEnabled, isPersistent, isSelectable, notifyChanged, notifyDependencyChange, notifyHierarchyChanged, onAttachedToActivity, onAttachedToHierarchy, onBindView, onCreateView, onDependencyChanged, onPrepareForRemoval, performClick, persistBoolean, persistFloat, persistInt, persistLong, persistString, requireKey, restoreHierarchyState, saveHierarchyState, setDefaultValue, setDependency, setEnabled, setIntent, setKey, setLayoutResource, setOnPreferenceChangeInternalListener, setOnPreferenceChangeListener, setOnPreferenceClickListener, setOrder, setPersistent, setSelectable, setShouldDisableView, setSummary, setSummary, setTitle, setTitle, setWidgetLayoutResource, shouldCommit, shouldPersist, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

EditTextPreference

public EditTextPreference(Context context,
                          AttributeSet attrs,
                          int defStyle)

EditTextPreference

public EditTextPreference(Context context,
                          AttributeSet attrs)

EditTextPreference

public EditTextPreference(Context context)
Method Detail

setText

public void setText(String text)
Saves the text to the SharedPreferences.

Parameters:
text - The text to save

getText

public String getText()
Gets the text from the SharedPreferences.

Returns:
The current preference value.

onBindDialogView

protected void onBindDialogView(View view)
Description copied from class: DialogPreference
Binds views in the content View of the dialog to data.

Make sure to call through to the superclass implementation.

Overrides:
onBindDialogView in class DialogPreference
Parameters:
view - The content View of the dialog, if it is custom.

onAddEditTextToDialogView

protected void onAddEditTextToDialogView(View dialogView,
                                         EditText editText)
Adds the EditText widget of this preference to the dialog's view.

Parameters:
dialogView - The dialog view.

onDialogClosed

protected void onDialogClosed(boolean positiveResult)
Description copied from class: DialogPreference
Called when the dialog is dismissed and should be used to save data to the SharedPreferences.

Overrides:
onDialogClosed in class DialogPreference
Parameters:
positiveResult - Whether the positive button was clicked (true), or the negative button was clicked or the dialog was canceled (false).

onGetDefaultValue

protected Object onGetDefaultValue(TypedArray a,
                                   int index)
Description copied from class: Preference
Called when 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).

Overrides:
onGetDefaultValue in class Preference
Parameters:
a - The set of attributes.
index - The index of the default value attribute.
Returns:
The default value of this preference type.

onSetInitialValue

protected void onSetInitialValue(boolean restoreValue,
                                 Object defaultValue)
Description copied from class: Preference
Implement this to set the initial value of the Preference. If the restoreValue flag is true, you should restore the value from the shared preferences. If false, you should set (and possibly store to shared preferences if Preference.shouldPersist()) to defaultValue.

This may not always be called. One example is if it should not persist but there is no default value given.

Overrides:
onSetInitialValue in class Preference
Parameters:
restoreValue - Whether to restore the persisted value (true), or use the given default value (false).
defaultValue - The default value. Only use if restoreValue is false.

shouldDisableDependents

public boolean shouldDisableDependents()
Description copied from class: Preference
Should return whether this preference's dependents should currently be disabled.

Overrides:
shouldDisableDependents in class Preference
Returns:
True if the dependents should be disabled, otherwise false.

getEditText

public EditText getEditText()
Returns the EditText widget that will be shown in the dialog.

Returns:
The EditText widget that will be shown in the dialog.

onSaveInstanceState

protected Parcelable onSaveInstanceState()
Description copied from class: Preference
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.

Overrides:
onSaveInstanceState in class DialogPreference
Returns:
Returns a Parcelable object containing the preference's current dynamic state, or null if there is nothing interesting to save. The default implementation returns null.
See Also:
Preference.onRestoreInstanceState(android.os.Parcelable), Preference.saveHierarchyState(android.os.Bundle), Preference.dispatchSaveInstanceState(android.os.Bundle)

onRestoreInstanceState

protected void onRestoreInstanceState(Parcelable state)
Description copied from class: Preference
Hook allowing a preference to re-apply a representation of its internal state that had previously been generated by Preference.onSaveInstanceState(). This function will never be called with a null icicle.

Overrides:
onRestoreInstanceState in class DialogPreference
Parameters:
state - The frozen state that had previously been returned by Preference.onSaveInstanceState().
See Also:
Preference.onSaveInstanceState(), Preference.restoreHierarchyState(android.os.Bundle), Preference.dispatchRestoreInstanceState(android.os.Bundle)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature