FileDocCategorySizeDatePackage
YesNoPreference.javaAPI DocAndroid 5.1 API4724Thu Mar 12 22:22:10 GMT 2015com.android.internal.preference

YesNoPreference

public class YesNoPreference extends android.preference.DialogPreference
The {@link YesNoPreference} is a preference to show a dialog with Yes and No buttons.

This preference will store a boolean into the SharedPreferences.

Fields Summary
private boolean
mWasPositiveResult
Constructors Summary
public YesNoPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr, int defStyleRes)

        super(context, attrs, defStyleAttr, defStyleRes);
    
public YesNoPreference(android.content.Context context, android.util.AttributeSet attrs, int defStyleAttr)

        this(context, attrs, defStyleAttr, 0);
    
public YesNoPreference(android.content.Context context, android.util.AttributeSet attrs)

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

        this(context, null);
    
Methods Summary
public booleangetValue()
Gets the value of this preference.

return
The value of the preference.

        return mWasPositiveResult;
    
protected voidonDialogClosed(boolean positiveResult)

        super.onDialogClosed(positiveResult);

        if (callChangeListener(positiveResult)) {
            setValue(positiveResult);
        }
    
protected java.lang.ObjectonGetDefaultValue(android.content.res.TypedArray a, int index)

        return a.getBoolean(index, false);
    
protected voidonRestoreInstanceState(android.os.Parcelable state)

        if (!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());
        setValue(myState.wasPositiveResult);
    
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.wasPositiveResult = getValue();
        return myState;
    
protected voidonSetInitialValue(boolean restorePersistedValue, java.lang.Object defaultValue)

        setValue(restorePersistedValue ? getPersistedBoolean(mWasPositiveResult) :
            (Boolean) defaultValue);
    
public voidsetValue(boolean value)
Sets the value of this preference, and saves it to the persistent store if required.

param
value The value of the preference.

        mWasPositiveResult = value;
        
        persistBoolean(value);
        
        notifyDependencyChange(!value);
    
public booleanshouldDisableDependents()

        return !mWasPositiveResult || super.shouldDisableDependents();