Reputation: 3580
I have an EditText
field, where the user can switch between two kind of keyboards (alphabetic and numeric only). This works great, but when the user wants to paste a specific string, e.g. AB12AB
and the numeric keyboard is currently opened, it will just paste 12
(cut all non-digits out) into the field.
For switching keybords, I currently use the method .setInputType(...)
, but the problem is, that every string which is pasted into the textfield will be filtered by the currently set InputType.
How can I paste any kind of strings into the textfield without being restricted by the currently set InputType?
Upvotes: 2
Views: 198
Reputation: 3580
Statically this problem can be solved by adding:
android:digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
to the .xml file of the EditText object. It is important, that android:inputType="number"
is also set, otherwise it won't work.
Every time the InputMethod of the EditText object is changed dynamically, the current attribute is overriden, so if you want to add the android:digits="..."
attribute back, you can achieve that by adding a KeyListener:
.setKeyListener(DigitsKeyListener.getInstance("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"));
Note that setting the DigitsKeyListener will also set an InputType (see in reference), so you don't have to call .setInputType(...)
again.
Upvotes: 0
Reputation: 883
android:digits="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Upvotes: 1