I'm trying to devise an input type for a field which will accept credit card numbers.
I had been using inputType="number" - but that won't let people with hardware keyboards hit the space bar.. when they do it jumps to another field in the activity.
I'd like to allow users to use a space in their numbers if they want, or, at least, make it so that if users with a hardware keyboard hit the space when I'm only allowing numbers it won't leave the credit card number EditText.
Ideally I'd be able to implement some interface and have my own custom inputType, but I'm not sure that's possible.
Is it possible to allow numbers and spaces, while showing the numbers soft keyboard?
The best choise is InputType.TYPE_CLASS_DATETIME
How about android:inputType="phone" in your layout xml file?
I don't have a definitive answer for you but here are some resources I picked up:
I found this clue to "catch" hard key presses: "To intercept hard keys, override InputMethodService.onKeyDown()". Read from bottom heading "Intercepting hard key events".
If you can't find a way to intercept and deal with the "space" key, I would suggest using a normal TextView and manually opening the number keyboard rather than the qwerty one (Go here for more info on general Input Reference). You can then validate key pressed from the hard keyboard.
Sorry I couldn't give you a more solid answer!
Related
Is there a way to find out the current keyboard layout?
I.e.: the typical layout is QWERTY but, e.g., Germany usually has QWERTZ, etc.
Also, I've seen some older Android phones without digits row on the main keyboard page.
Is it possible to find out if the current keyboard layout has also digits row? (Digits row without long touch) And potentially other "non standard" things?
Is there a way to find out current keyboard layout ?
Unless you mean "the keyboard that is visible to the user right this instant", there is no concept of a "current keyboard layout" in Android. A user may have 0-N input method editor implementations available to them, choosing among them as the user sees fit. Plus, depending on circumstances (e.g., inputType hints), an input method editor can display different input options.
Is it possible to find out if the current keyboard layout has there also digits row ?
No.
And potentially other "nonstandard" things ?
No.
I know that you can specify a short message input type in order to turn the enter key of the keyboard into an emoji button and pressing it will show up the emoji list but what i want to do is open up the emoji list programatically from a button. Is this possible?
There is no functionality to add tabs to any generic keyboard. Certain keyboards may support it, but it isn't a common feature. You could write your own fully custom keyboard, but that's a lot of work and will piss off many users.
Also, I'm not sure what you mean about by like in hangouts. I use hangouts- it doesn't do anything odd with my keyboard. It stays as Swype, there's no special emoji tab. It may be a feature of your favorite keyboard based on the input type (I assume both use input type textShortMessage). But it isn't a generic feature.
See Link Android Keyboard with Emoji
Thanks and enjoy...
In my application I have an EditText (Actually it's an implementation of MultiAutoCompleteTextView, but I don't think that matters) in which the user can enter a formula to be calculated, although generally they will want to just enter an integer.
What I would really like is for the keyboard to open with the numeric keyboard showing, but allow them to change to text if they want.
As standard of course it shows the letters and allwos them to change to numbers, which is OK, but 90% of the time they will want the numbers.
I tried doing:
operandEditText.setInputType(InputType.TYPE_CLASS_NUMBER|
InputType.TYPE_NUMBER_FLAG_SIGNED|InputType.TYPE_CLASS_TEXT);
But the result was a numeric keypad with letters written on the number keys (like a phone keypad), and it didn't write letters anyway.
I'm also aware that I could add a button, spinner or something that changed the input mode of the widget, but the aim of this is to make the interface easier to use, and I'm not sure adding another control will achieve that.
Is there a way to make it do what I want?
I have an OpenGL application that needs to show the soft keyboard for devices without physical ones for user input such as username or numbers in a few cases. In the case of numeric input, is there any way to show the numeric keypad instead of the alphabetic keyboard? I'm not using any text edit fields or anything, just the InputMethodManager:
((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE)).showSoftInput(glView, InputMethodManager.SHOW_FORCED);
The only method I've found that looks remotely helpful is InputMethodManager.setInputMethod but that takes an IBinder token and a String id, neither of which is explained very well in the documentation. I get the impression that it's not the right way to go, though.
If I were using an edit field, it would be simple and obvious, and I've found dozens of answers for that, but that's not what I'm doing, because it's an OpenGL game, so I have to just displaying the keyboard manually as above.
Probably not the answer you are looking for since it is more of a hack than a real solution, but a few things come to mind that might work (that is if you can't get a real solution).
An EditText with View.INVISIBLE set. Although, you might not be able to set focus here.
Put an EditText behind your GLSurfaceView and focus it. So it’s technically visible (from a code standpoint) but invisible to the user.
Specifically, how do I get it to pop up as the numbers entry screen but still be able to switch to letters? What I'd really like, ideally, is to have it act the same as if we had the xml property
<EditText
...
android:inputType="textShortMessage"/>
but come up on the number entry screen (the one you get by clicking "?123") on first showing, rather than the usual qwerty one. I've tried doing eg
<EditText
...
android:inputType="textShortMessage|number"/>
but all that does is default it to the phone-number-entry screen with no option to enter letters. Any ideas?
In Java code, use:
edittext.setRawInputType(InputType.TYPE_CLASS_NUMBER);
This discussion seems to indicate that you can use:
android:inputType="number"
to achieve what you are looking for. But I think the poster of that solution may have misunderstood the problem, as I believe that "number" will only allow (of course) numbers, and not allow letters. I am not able to test this at the moment, so I will have to speculate.
Alternately, you could have two EditTexts for your input: one EditText strictly numeric, and the other plain text, such that you could enter a quantity in the first field and a unit in the second field. I'm guessing that you are eventually parsing the input as a string anyhow, and in that case all you would have to do is concatenate the text before parsing.