Java – When set to Android 4.0, Eclipse does not recognize numberPassword?

When set to Android 4.0, Eclipse does not recognize numberPassword?… here is a solution to the problem.

When set to Android 4.0, Eclipse does not recognize numberPassword?

When I set the input type to “numberPassword”, the Eclipse editor does not recognize the input type in the field, the code is as follows:

<EditText
    android:id="@+id/pin_field"
    android:layout_width="236dp"
    android:layout_height="wrap_content"
    android:inputType="numberPassword">

<requestFocus />
</EditText>

This is the error I got on the “android:inputType” line :

"error: Error: String types not allowed (at 'inputType' with value 'numberPassword')."

In the Graph Layout tab at the top, I changed the version from 2.3.3 to Android 4.0, I read that it might fix it, but it doesn’t seem to work. I may have missed something obvious but couldn’t figure it out.

This is the Android documentation for inputType and ‘numberPassword’: http://developer.android.com/reference/android/R.attr.html#inputType

Solution

<EditText
    android:id="@+id/pin_field"
    android:layout_width="236dp"
    android:layout_height="wrap_content"
    android:inputType="number"
    android:password="true"
    <requestFocus />
</EditText>

Try the code above instead of yours

Or you can also set it dynamically through the following code

editText.setInputType( InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_VARIATION_PASSWORD);

Update::
With a code set like the following, the InputFilter accepts only letters or numbers, or both

edittext.setFilters(new InputFilter[] {
    new InputFilter() {
        public CharSequence filter(CharSequence src, int start,
                int end, Spanned dst, int dstart, int dend) {
            if(src.equals("")){ // for backspace
                return src;
            }
            if(src.toString().matches("[a-zA-Z0-9 ]+")){
                return src;
            }
            return "";
        }
    }
});

Please test thoroughly!

Related Problems and Solutions