Android Keyboard with number and decimal for LG G4 - android

I am using the following element in the Android EditText, to have a keyboard with number and decimal for displaying a keyboard layout for amount input (for eg 22.12).
android:inputType="numberDecimal"
It is working for all devices, like Samsung, Nexus, Sony etc.
The keyboard layout looks like below.
The keyboard layout on the LG G4 looks like below.
Could anyone please help, how to have decimal keyboard for the LG G4. I have already tried the android:inputType="phone", still same issue.
I would like to stick to the decimal input, as it would not be very nice to have a full alpha-numeric keyboard, to enter amount.
Thanks in advance.

UPDATE
It seems that flag signed is not needed after all to get decimal separator, It was actually the TYPE_TEXT_FLAG_NO_SUGGESTIONS that messed up the keyboard so do not use it with number input types. Also noticed that LG keyboard looks different depending on if you set the input type from code vs. XML
END UPDATE
It seems like the combination of inputType and digits solves the problem. I have a class that extends EditText so I initialize the EditText like this:
setKeyListener(DigitsKeyListener.getInstance("0123456789.,"));
setRawInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL | InputType.TYPE_NUMBER_FLAG_SIGNED);
I guess that because LG has bundled decimal separator and minus sign in a same button you have to configure both feature on and then disable "-" by not including it in digits.

There are 2 possible ways i can think of, but i do not have an LG make phone, so i personally couldn't test any of these. But still its worth a shot.
Try to give the input type as android:inputType="phone".
Saw this on the dev site, more details here https://developer.android.com/training/keyboard-input/style.html#Type
This one i tried a couple of years back, it worked for me, but my case was different. Specify an attribute in your EditText item in xml.
android:digits="0123456789."
What it does is, sets the view to accept numeric input and only the specific items mentioned in the digits attribute. I personally do not use it much, its more of a hack than a solution, but it gets things done. More info on the below link:
https://developer.android.com/reference/android/widget/TextView.html
Try these out, hope they help for all cases.

Related

setInputType(InputType.TYPE_NUMBER_FLAG_DECIMAL) brings normal (letters) keyboard

I am setting (programmatically) the input type of several EditText that way, so keyboard with only numbers pops up to the user. But it is not working, the normal keyboard, with letters, appears. If I set them to setInputType(InputType.TYPE_CLASS_NUMBER) appears the keyboard I want, but I am not able to set a decimal value. Dot simply doesn't appear. I tried with setRawInputType, but it does not work neither. i was not able to find a question here in SO regarding that issue.
Is that a bug, or something I am not doing well? How could I show the numeric keyboard, and be able to assign a decimal value?
As a side note, i am using an Experia M2 to try.
Thank you.
Found the solution, you need to set BOTH types:
Java:
editText.setInputType(InputType.TYPE_CLASS_NUMBER | InputType.TYPE_NUMBER_FLAG_DECIMAL);
Kotlin:
editText.inputType = InputType.TYPE_CLASS_NUMBER or InputType.TYPE_NUMBER_FLAG_DECIMAL

prefered input type EditText [duplicate]

This question already has answers here:
EditText with number keypad by default, but allowing alphabetic characters
(19 answers)
Closed 9 years ago.
This has been asked elsewhere online to no avail. Is there any way in Android to display the numeric soft keyboard when focusing on an EditText, but still allow any text to be entered?
I'd like to let the user enter quantities (e.g. "1 kg", "2 L"), so just setting inputType="number" won't work.
Add the following line of code, and it will do the trick :)
editText.setRawInputType(Configuration.KEYBOARD_QWERTY);
This will show the the numeric keypad first, but also allows you to enter free text.
More information here.
This may be device dependant but have you tried:
android:inputType="phone"
All Input Types Link
in the EditText's xml , this gives you the number pad keyboard but then you can still switch to letter's if you want. (Atleast on my Nexus One).
Note that: setRawInputType(InputType.TYPE_CLASS_NUMBER);
has the desired effect on some devices but not others...
On htc it works fine however on galaxy tab II you only get the numeric keyboard and no way to switch back to alpha.
write the code in XML,
android:numeric="integer"
android:inputType="phone"
android:digits="1234567890"
It looks like the underlying question you're dealing with is: how can I allow the user to enter quantities?
One appropriate answer is: with a numeric input, paired with some form of category select for the unit. e.g. radio, dropdown, or spinner. This is probably easier to use and also saves you the headache of having to validate your input every time.
You could also just have iron cojones and write a custom soft keyboard.
I tried many different combinations before I figured this out, but this appears to work correctly:
setRawInputType(InputType.TYPE_CLASS_NUMBER);
The key lies in the description for setRawInputType(int):
Directly change the content type integer of the text view, without
modifying any other state.

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 do I default to numeric keyboard on EditText without forcing numeric input? [duplicate]

This question already has answers here:
EditText with number keypad by default, but allowing alphabetic characters
(19 answers)
Closed 9 years ago.
This has been asked elsewhere online to no avail. Is there any way in Android to display the numeric soft keyboard when focusing on an EditText, but still allow any text to be entered?
I'd like to let the user enter quantities (e.g. "1 kg", "2 L"), so just setting inputType="number" won't work.
Add the following line of code, and it will do the trick :)
editText.setRawInputType(Configuration.KEYBOARD_QWERTY);
This will show the the numeric keypad first, but also allows you to enter free text.
More information here.
This may be device dependant but have you tried:
android:inputType="phone"
All Input Types Link
in the EditText's xml , this gives you the number pad keyboard but then you can still switch to letter's if you want. (Atleast on my Nexus One).
Note that: setRawInputType(InputType.TYPE_CLASS_NUMBER);
has the desired effect on some devices but not others...
On htc it works fine however on galaxy tab II you only get the numeric keyboard and no way to switch back to alpha.
write the code in XML,
android:numeric="integer"
android:inputType="phone"
android:digits="1234567890"
It looks like the underlying question you're dealing with is: how can I allow the user to enter quantities?
One appropriate answer is: with a numeric input, paired with some form of category select for the unit. e.g. radio, dropdown, or spinner. This is probably easier to use and also saves you the headache of having to validate your input every time.
You could also just have iron cojones and write a custom soft keyboard.
I tried many different combinations before I figured this out, but this appears to work correctly:
setRawInputType(InputType.TYPE_CLASS_NUMBER);
The key lies in the description for setRawInputType(int):
Directly change the content type integer of the text view, without
modifying any other state.

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