Eclipse doesn't recognize numberPassword when installed on Android 4.0?

Eclipse editor doesn't recognize inputType in field when I put it as "numberPassword", here's the code:

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

    <requestFocus />
</EditText>

      

Here's the error I'm getting on the "android: inputType" line:

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

      

And in the Graphic Layout tab at the top, I changed the version from 2.3.3 to Android 4.0, which I read, I can fix it, but it didn't seem to work. I probably missed something obvious but can't figure it out.

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

+3


source to share


2 answers


The comment on the newsletter gave me the key that I need

"Is the Android build project set to 4.0?"



I had a minSdk file in my manifest file as API level 14 which is 4.0 and correct, which threw me away from the real problem. I had a project build target in Eclipse set to 2.3.3 that needed to be changed to 4.0.

+1


source


<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 above code instead of code

or you can dynamically set the code below

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

      



Updated :: Via code, set the InputFilter as shown below to accept alphabets only or numeric 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 it thoroughly!

+3


source







All Articles