FileDocCategorySizeDatePackage
EditTextPreference.javaAPI DocAndroid 1.5 API7010Wed May 06 22:41:56 BST 2009android.preference

EditTextPreference

public class EditTextPreference extends DialogPreference
A {@link Preference} that allows for string input.

It is a subclass of {@link DialogPreference} and shows the {@link EditText} in a dialog. This {@link EditText} can be modified either programmatically via {@link #getEditText()}, or through XML by setting any EditText attributes on the EditTextPreference.

This preference will store a string into the SharedPreferences.

See {@link android.R.styleable#EditText EditText Attributes}.

Fields Summary
private android.widget.EditText
mEditText
The edit text shown in the dialog.
private String
mText
Constructors Summary
public EditTextPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyle)

        super(context, attrs, defStyle);
        
        mEditText = new EditText(context, attrs);
        
        // Give it an ID so it can be saved/restored
        mEditText.setId(com.android.internal.R.id.edit);
        
        /*
         * The preference framework and view framework both have an 'enabled'
         * attribute. Most likely, the 'enabled' specified in this XML is for
         * the preference framework, but it was also given to the view framework.
         * We reset the enabled state.
         */
        mEditText.setEnabled(true);
    
public EditTextPreference(android.content.Context context, android.util.AttributeSet attrs)

        this(context, attrs, com.android.internal.R.attr.editTextPreferenceStyle);
    
public EditTextPreference(android.content.Context context)

        this(context, null);
    
Methods Summary
public android.widget.EditTextgetEditText()
Returns the {@link EditText} widget that will be shown in the dialog.

return
The {@link EditText} widget that will be shown in the dialog.

        return mEditText;
    
public java.lang.StringgetText()
Gets the text from the {@link SharedPreferences}.

return
The current preference value.

        return mText;
    
protected voidonAddEditTextToDialogView(android.view.View dialogView, android.widget.EditText editText)
Adds the EditText widget of this preference to the dialog's view.

param
dialogView The dialog view.

        ViewGroup container = (ViewGroup) dialogView
                .findViewById(com.android.internal.R.id.edittext_container);
        if (container != null) {
            container.addView(editText, ViewGroup.LayoutParams.FILL_PARENT,
                    ViewGroup.LayoutParams.WRAP_CONTENT);
        }
    
protected voidonBindDialogView(android.view.View view)

        super.onBindDialogView(view);

        EditText editText = mEditText;
        editText.setText(getText());
        
        ViewParent oldParent = editText.getParent();
        if (oldParent != view) {
            if (oldParent != null) {
                ((ViewGroup) oldParent).removeView(editText);
            }
            onAddEditTextToDialogView(view, editText);
        }
    
protected voidonDialogClosed(boolean positiveResult)

        super.onDialogClosed(positiveResult);
        
        if (positiveResult) {
            String value = mEditText.getText().toString();
            if (callChangeListener(value)) {
                setText(value);
            }
        }
    
protected java.lang.ObjectonGetDefaultValue(android.content.res.TypedArray a, int index)

        return a.getString(index);
    
protected voidonRestoreInstanceState(android.os.Parcelable state)

        if (state == null || !state.getClass().equals(SavedState.class)) {
            // Didn't save state for us in onSaveInstanceState
            super.onRestoreInstanceState(state);
            return;
        }
         
        SavedState myState = (SavedState) state;
        super.onRestoreInstanceState(myState.getSuperState());
        setText(myState.text);
    
protected android.os.ParcelableonSaveInstanceState()

        final Parcelable superState = super.onSaveInstanceState();
        if (isPersistent()) {
            // No need to save instance state since it's persistent
            return superState;
        }
        
        final SavedState myState = new SavedState(superState);
        myState.text = getText();
        return myState;
    
protected voidonSetInitialValue(boolean restoreValue, java.lang.Object defaultValue)

        setText(restoreValue ? getPersistedString(mText) : (String) defaultValue);
    
public voidsetText(java.lang.String text)
Saves the text to the {@link SharedPreferences}.

param
text The text to save

        final boolean wasBlocking = shouldDisableDependents();
        
        mText = text;
        
        persistString(text);
        
        final boolean isBlocking = shouldDisableDependents(); 
        if (isBlocking != wasBlocking) {
            notifyDependencyChange(isBlocking);
        }
    
public booleanshouldDisableDependents()

        return TextUtils.isEmpty(mText) || super.shouldDisableDependents();