7

I need the user to enter text in a Edit Text with custom keyboard options. That is, I need the keypad to show only "S","A","B","C","D","E" and "F" characters. Is it possible to implement this?

Darshan Gowda
  • 4,956
  • 3
  • 19
  • 27

1 Answers1

6

Much easier solution is to add digit parameter in xml definition of EditText like following:

android:digits="SABCDEF"
android:inputType="textNoSuggestions"

Shown keyboard will have all characters but when user try to enter any of not allowed that will be ignored.

Hope this helps

Edit: textNosuggestions to textNoSuggestions

vidulaJ
  • 1,232
  • 1
  • 16
  • 31
Ewoks
  • 12,285
  • 8
  • 58
  • 67
  • 1
    Is there any sollution to write that programically, not in xml? – Dominika Apr 16 '16 at 08:39
  • in my opinion there is no reason for that. You don't want to change in runtime what user can enter in one text field – Ewoks Apr 16 '16 at 08:42
  • I make the field of editTexts dynamically. So I need it. The application creates matrix, the input can be only 1234567890./- . But I cant find solution for this combination. – Dominika Apr 16 '16 at 08:50
  • cell.setInputType(InputType.TYPE_CLASS_NUMBER); But it is not all I wanted. The / is missing. – Dominika Apr 16 '16 at 08:51
  • 1
    Once again I strongly advice that you define your EditText in xml not in a runtime. Debugging such a created UI can be real pain (from my own experience), and in 99% cases there is no reason to create Views in runtime like that.. If you really want to do it so maybe this would help .setKeyListener(DigitsKeyListener.getInstance("0123456789./-")); – Ewoks Apr 16 '16 at 09:10
  • This is exactly what I was looking for. Thank you! – Dominika Apr 16 '16 at 09:12
  • Pay attention to whole comment again and try to define Views in xml please. – Ewoks Apr 16 '16 at 09:13
  • I see. Dimension of matrix is setup in runtime. Based on input from user. So thats why I create also field of ediTexts dynamically . I dont know, how to set editTexts dynamically in xml. Do you have any advice? – Dominika Apr 16 '16 at 09:17