-1

An edittext should take only a character, but when given multiple characters the edittext accepts. It forces me to erase the given text. I want my edittext to necessarily accept any one of the texts "S,A,Q,W,R,B,C,D,E,U" and edittext shouldn't accept any other characters other than given characters in android. I need code in java, not in xml.

Ankit Shubham
  • 2,989
  • 2
  • 36
  • 61
prabu S
  • 77
  • 1
  • 2
  • http://stackoverflow.com/questions/14192199/validation-allow-only-number-and-characters-in-edit-text-in-android Have a look :) – Jhaman Das Apr 12 '16 at 09:08
  • Check my [answer](http://stackoverflow.com/questions/36568485/an-edittext-should-take-only-a-character/36568582#36568582) and see if that works for you. – Rohit Arya Apr 12 '16 at 10:14

2 Answers2

1

Since you have written:

i need code in java. not in xml.

Try this:

editText.setKeyListener(DigitsKeyListener.getInstance("SAQWRBCDEU"));
Rohit Arya
  • 6,751
  • 1
  • 26
  • 40
0

Try Following code

<EditText
    android:id="@+id/editText1"
    android:digits="SAQWRBCDEU"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" />
mdDroid
  • 3,135
  • 2
  • 22
  • 34