Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude special characters from android keypad for EditText

Tags:

Hi I want to show only numbers and characters on the keypad for EditText in android, I did try to add the attribute android:inputType = text|number but it did not work.

Please help me with any other better suggestion. thanks in advance.

like image 531
learner Avatar asked Sep 07 '11 14:09

learner


People also ask

How do I edit EditText Uneditable?

If you want your disabled EditText to look the same as your enabled one, you should use android:enabled="false" in combination with android:textColor="..." . Show activity on this post. Used this if you have an icon to be clickable, this works for me.

How do you make EditText editable?

We can set editable property of EditText in XML layout but not programatically, but there is no setEditable() method! If EditText is not Enabled [ by setEnabled(false) ] it still Editable!


1 Answers

Use the filter for that. Here I am adding the code for filter.

  EditText etName = (EditText)findViewById(R.id.etName);   InputFilter filter = new InputFilter() {          @Override         public CharSequence filter(CharSequence source, int start, int end, Spanned dest, int dstart, int dend) {              for (int i = start; i < end; i++) {                  if (!Character.isLetterOrDigit(source.charAt(i))) {                      return "";                  }              }              return null;          }   };   etName.setFilters(new InputFilter[]{filter});  
like image 191
Aju Avatar answered Sep 21 '22 05:09

Aju