-2

I have an android app where I accept various inputs from the user but the problem is that i am not able to use space in any of the EditText fields I dont know what the problem is and is very frustrating...Any help would be appriciated.

<EditText
        android:id="@+id/edt_frm_place"
        style="@style/Normal_CustomFontStyle"
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:background="@drawable/border"
        android:paddingLeft="3dp"
        android:maxLength="50"
        android:paddingTop="3dp"

         android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
        android:hint="Enter From Place" />

This is my EditText xml representation

darshan kodkany
  • 51
  • 1
  • 1
  • 8

4 Answers4

3

Try this way,I hope it will helps you .

Just update your EditText Like this

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890,"","

Or

 EditText yourEditText = (EditText) findViewById(R.id.yourEditText);
yourEditText.setFilters(new InputFilter[] {
    new InputFilter() {
        @Override
        public CharSequence filter(CharSequence cs, int start,
                    int end, Spanned spanned, int dStart, int dEnd) {
            // TODO Auto-generated method stub
            if(cs.equals("")){ // for backspace
                 return cs;
            }
            if(cs.toString().matches("[a-b-c-d-...-A-1-..0 ]+")){
                 return cs;
            }
            return "";
        }
    }
});
IntelliJ Amiya
  • 74,896
  • 15
  • 165
  • 198
2

change

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"

to

android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "

which include space

techroid
  • 477
  • 4
  • 11
0

Use following codes

 EditText yourEditText = (EditText) findViewById(R.id.yourEditText);
  yourEditText.setFilters(new InputFilter[] {
  new InputFilter() {
    @Override
    public CharSequence filter(CharSequence cs, int start,
                int end, Spanned spanned, int dStart, int dEnd) {
        // TODO Auto-generated method stub
        if(cs.equals("")){ // for backspace
             return cs;
        }
        if(cs.toString().matches("[a-zA-Z ]+")){
             return cs;
        }
        return "";
    }
}
});
sasikumar
  • 12,540
  • 3
  • 28
  • 48
0

You just have to incluse " " in android:digit property because this property defines all the characters you could enter in Edittext and you didn't specify space in it. SO just add a " " after 0 and it will work

Sahil Garg
  • 263
  • 1
  • 20