Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Space Bar Is Not Working

In my Android project I have restricted Edittext to allow only Alphanumeric characters. I have using below code snippet to achieve this

    <EditText
            android:id="@+id/edt_text"
            android:layout_width="140dp"      
            android:layout_height="wrap_content"                                   
            android:layout_margin="5dp"                                                 
            android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
            android:ems="10"
            android:imeOptions="actionNext"
            android:maxLength="8"
            android:padding="5dp"
            android:singleLine="true" />

But while using this code if I tab the Space Bar showing in soft keypad it is acting as a BackSpacebutton and removing the characters in EditText. Anyone please help me to solve this issue.

like image 261
Jamal Avatar asked Oct 31 '22 06:10

Jamal


2 Answers

You can also handle this Programetically.

mEditText1.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            if (s.equals(" ")) {
                mEditText1.getText().toString().trim();
            }
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

I hope it may help you. :)

like image 88
Ronak Selarka Avatar answered Nov 11 '22 11:11

Ronak Selarka


I know it's very too late, but the problem is in the input digit restriction you have set.

sample

like image 23
RoCk RoCk Avatar answered Nov 11 '22 12:11

RoCk RoCk