Isak
Isak

Reputation: 1

Android EditText InputType, numeric keyboard + append text

I have this EditText where the user enter a credit card number. I add a blank space every 4 characters by appending to the EditText like so:

cardNumberEditText.append(" ");

I only want to show the numeric keyboard. Therefore I add this attribute to my EditText in XML:

android:inputType="number"

However this doesn't allow me to append anything to the EditText apart from numbers.

I could change the XML attribute to:

android:inputType="number|text"

but this would change the keyboard layout thus allowing the user to also enter text which I don't want.

The "add new payment method" in the Play Store app does what I'm after but I just can't figure out how they do it.

Upvotes: 0

Views: 1707

Answers (1)

SeanKelleyx
SeanKelleyx

Reputation: 1155

When you use inputType="number" it disables " " and "-" chars. You can keep using this type and specify that the " " char should be counted as a digit by specifying digits="0123456789 " in the layout xml as well.

Upvotes: 3

Related Questions