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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.