Android Space Bar not working

In my Android project, I restricted Edittext to only allow Alphanumeric characters. I use the code snippet below 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 when using this code, if I insert the Space Bar into the soft keypad , it acts like a BackSpace button and removes characters in the Edittext . Someone please help me solve this problem.

+5
source share
4 answers

use this RegEx, it will return true, if it is an alphanumeric expression, it will return false.

 public boolean isAlphaNumeric(String s){ String pattern= "^[a-zA-Z0-9]*$"; if(s.matches(pattern)){ return true; } return false; } 
+1
source

You can also handle this program.

 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) { } }); 

Hope this can help you. :)

+1
source

I know this is too late, but the problem is the input value you set.

sample

+1
source

How to allow a space to create a space and just delete it programmatically?

0
source

Source: https://habr.com/ru/post/1246530/


All Articles