package com.example.android.sunshine;

import android.content.Context;
import android.content.res.TypedArray;
import android.preference.EditTextPreference;
import android.util.AttributeSet;

/**
 * @author George Spiridakis <george@codeburrow.com>
 * @since May/22/2016.
 * ===================================================
 * ---------->    http://codeburrow.com    <----------
 * ===================================================
 */
public class LocationEditTextPreference extends EditTextPreference {

    private static final int DEFAULT_MINIMUM_LOCATION_LENGTH = 2;

    private int mMinLength;

    public LocationEditTextPreference(Context context, AttributeSet attrs) {
        super(context, attrs);
        TypedArray a = context.getTheme().obtainStyledAttributes(
                attrs,
                R.styleable.LocationEditTextPreference,
                0,
                0
        );

        try {
            mMinLength = a.getInteger(R.styleable.LocationEditTextPreference_minLength, DEFAULT_MINIMUM_LOCATION_LENGTH);
        } finally {
            a.recycle();
        }
    }

}
@@ -32,16 +32,75 @@
 shine;%0A%0A
+import android.app.AlertDialog;%0Aimport android.app.Dialog;%0A
 import a
@@ -162,16 +162,42 @@
 dArray;%0A
+import android.os.Bundle;%0A
 import a
@@ -253,24 +253,149 @@
 oid.
-util.AttributeSe
+text.Editable;%0Aimport android.text.TextWatcher;%0Aimport android.util.AttributeSet;%0Aimport android.widget.Button;%0Aimport android.widget.EditTex
 t;%0A%0A
@@ -1309,9 +1309,1220 @@
 %0A    %7D%0A%0A
+    @Override%0A    protected void showDialog(Bundle state) %7B%0A        super.showDialog(state);%0A%0A        EditText editText = getEditText();%0A        editText.addTextChangedListener(new TextWatcher() %7B%0A            @Override%0A            public void beforeTextChanged(CharSequence s, int start, int count, int after) %7B%0A%0A            %7D%0A%0A            @Override%0A            public void onTextChanged(CharSequence s, int start, int before, int count) %7B%0A%0A            %7D%0A%0A            @Override%0A            public void afterTextChanged(Editable s) %7B%0A                Dialog dialog = getDialog();%0A                if (dialog instanceof AlertDialog) %7B%0A                    AlertDialog alertDialog = (AlertDialog) dialog;%0A                    Button positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE);%0A                    // Check if the EditText is empty.%0A                    if (s.length() %3C mMinLength)%7B%0A                        // Disable OK button.%0A                        positiveButton.setEnabled(false);%0A                    %7D else %7B%0A                        // Re-enable the button.%0A                        positiveButton.setEnabled(true);%0A                    %7D%0A                %7D%0A            %7D%0A        %7D);%0A    %7D%0A
 %7D

Use a text changed listener to disable and enable the positive button on the associated AlertDialog as the user enters text. Setting Limits, Part 2.