How to know if the keyboard layout changes between numbers and letters? - android

I have an EditText where users normaly enter numbers. Therefore I'm using InputType.TYPE_CLASS_NUMBER to get a numerical soft keyboard. Occationally though, some users may want to enter letters, so I have a button that switches between InputType.TYPE_CLASS_NUMBER and InputType.TYPE_CLASS_TEXT.
Works fine, but I found that this behaviour becomes very strange on devices with a hardware keyboard. I found this answer that solves that issue, so that I can exclude the keyboard switching functionality for those devices.
But then there are also devices, e.g. my asus transformer prime tablet, that never changes the software keyboard layout when switching between InputType.TYPE_CLASS_NUMBER and InputType.TYPE_CLASS_TEXT. How can i know if the software keyboard will change the layout or not?

How can i know if the software keyboard will change the layout or not?
You can't. InputType is a hint, not a demand. Some input method editors ("software keyboards") don't even have buttons (see Graffiti). There is no means of interrogating the system to determine the capability of input method editors, largely because the authors of input method editors do not have to declare their capabilities. They can honor or ignore InputType, etc. as they see fit.

Related

Finding out the keyboard layout

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.

Android - Set EditText keyboard input type to symbols and numbers ("?123")

I have an editText and I want to make the number and symbols pad (the "?123") as the default input type since the user will mostly input numbers, slashes, and the percent sign.
I've look around the questions here, but those mostly show the number pad instead. I've tried the solution to this problem editText.setRawInputType(Configuration.KEYBOARD_QWERTY); but it shows the number pad on android 4.4.4.
Now I'm stuck because the input types in the xml do not seem to show the ?123 pad. I was thinking of doing it programatically instead but that seems to be a dead end as well.
Any ideas anyone?
There is no way to do that. All you can do is give it the input type. The keyboard itself will decide what to display based on the EditorInfo (which holds the input type and a few other pieces of information) and it will differ for each keyboard- remember that not all phones will use the default keyboard, and some OEMs (Samsung) have their own they replace the default with). Your only real option is to send a numeric inputType, and hope it displays what you want.
Try InputType instead of Configuration. Check this out.

How to pop-up the "?123" Android keyboard

I have an EditText which needs to process either numerical and/or alphabetical input depending on state. The user may enter either type of input in some circumstances. I've only been able to pop-up the "Phone" keyboard using setInputType (InputType.TYPE_CLASS_NUMBER); which works, but doesn't allow the user a way to get back to the QWERTY keyboard. Since most of the input is indeed numerical, I would like to present the user with the ?123 keyboard most of the time. They would only need to go back to the QWERTY keyboard a few times.
How can I pop-up the onscreen QWERTY keyboard for alphabetical input, and then pop-up the "?123" keyboard if it's numerical? I just want to save a step for the user so they don't have to hit the ?123 button on the QWERTY keyboard every time.
Update: This is the keyboard I would like visible. The reason is I would like the user to easily switch between Alphabetical input and Numerical input. There is no way to switch to the QWERTY keyboard from the "number pad". In my app, numerical input is required for 90% of the input so I would like to pop it up as a convenience. In other words, rather than having to switch to the numerical keyboard 90% of the time, they only need to switch to QWERTY 10% of the time
The call to input.setRawInputType(Configuration.KEYBOARD_QWERTY); works differently on Honeycomb and later versions of Gingerbread (brings up the number pad). On Gingerbread 2.2.3 it works the way I want. Honeycomb and 2.3.7 keyboard screengrabs are below for reference. I don't know why they are so different.
You can use several ways to use number keyboard.
Some are listed below,
Method 1:
add this attribute to your text field(EditText)
android:inputType="number"
Method 2:
use it programmatically
edittext.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
I believe this post answers your question.
In short add this to your code:
editText.setRawInputType(Configuration.KEYBOARD_QWERTY);

How to show the soft numeric keypad without an input field?

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.

Why are certain letters on emulator virtual keypad showing numbers in Android EditText with inputtype as "number"?

I have an EditText widget in my Android application with inputtype=number. It does restrict character to entry by number. However, when I type certain alphabetic keys on the emulator's keypad (not all of them) I see numbers appear in the edit box. For example, typing an "F" puts a "6" in the edit box, "D" puts a "5", etc. Why is this happening?
-- roschler
I've seen two things happen, depending if you're on the emulator or on the phone, and depending on the SDK version:
The full keyboard appears (older SDKs). The behavior is exactly what you said: you can only type numbers, but certain characters can also be typed, and are translated to numbers. That behavior is explained by what Aleadam said.
The soft phone keypad (mostly on modern SDKs and phones, as far as I've seen). The typical phone keypad appears... "2ABC", "3CDE" and so on...
On both situations, you will see that, in fact, only numbers can be entered, which is what we want. As an example, in preference screen, you can perfectly cast the Object newValue into a Integer and you won't have any problems.
I do that all the time, don't worry!
It emulates the portrait keyboards that can be used to dial numbers also. Nothing wrong with your particular widget :)
If you enable that tag the emulator keyboard works like a T9.
ABC will be 2
DEF will be 3
etc.
It's normal, it's not a bug!

Categories

Resources