Skip to content Skip to sidebar Skip to footer

How To SetOnClickListener() To OK Button Of An EditTextPreference Dialog?

Possible Duplicate: how to call the ok button in the EditTextPreference I want to validate the Inputs (enter 6 digits) of an EditTextPreference dialog box. This is how my (relev

Solution 1:

The author of the solution has moved his project from Google Code to GitHub. You can find the new project at https://github.com/Knickedi/android-toolbox and the links to the two files he was referring to validating DialogPreference and validating EditTextPreference


Solution 2:

This could be achieved using setOnPreferenceChangeListener()

public UpdatePasswordPreference(Context context, AttributeSet attrs) {


    this.setOnPreferenceChangeListener(new OnPreferenceChangeListener() 
    {   
        @Override
        public boolean onPreferenceChange(Preference preference, Object newValue) 
        {
            MobicopLogger.d("Preference input changed");
            try 
            {
                if(newValue.toString().length() != 6)
                    return false;
                else
                    return true;
            }
            catch(Exception e)
            {
                return false;
            }
        }

    });


}

Solution 3:

create a custom layout and apply it to the preference by the following override method :

@Override
protected void onPrepareDialogBuilder(AlertDialog.Builder builder) {
    super.onPrepareDialogBuilder(builder);    //To change body of overridden methods use File | Settings | File Templates.
    builder.setView(LayoutInflater.from(ctx).inflate(R.layout.custome_preference_layout,null));
}

Post a Comment for "How To SetOnClickListener() To OK Button Of An EditTextPreference Dialog?"