Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AppCompatEditText android:digits not working?

android:digits property of AppCompatEdittext not working properly as I aspect.

My XML

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:digits="12345" />

But when I press number 6,7,8,9,0 previous characters repeated? I don't know what's wrong with this?

like image 786
Nilesh Senta Avatar asked Nov 07 '25 21:11

Nilesh Senta


2 Answers

Add inputType="number":

<EditText
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:digits="12345"
    android:inputType="number"/>
like image 68
barq Avatar answered Nov 09 '25 12:11

barq


At first you should add android:inputType="number"

<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:digits="12345"
android:inputType="number"/>

Secondly

 private final TextWatcher  mTextEditorWatcher = new TextWatcher() {

                public void beforeTextChanged(CharSequence s, int start, int count, int after)
                {

                }

                public void onTextChanged(CharSequence s, int start, int before, int count)
                {
                     // Logic in here
                .setKeyListener(DigitsKeyListener.getInstance("12345"));
                }

                public void afterTextChanged(Editable s)
                {

                }
        };
like image 30
IntelliJ Amiya Avatar answered Nov 09 '25 10:11

IntelliJ Amiya