number keyboard input on android device and decimal key

i am trying to use a numeric/decimal  input with the soft keyboard in my App.

on the iOS devices it works perfectly as i can type in decimal numbers with input type set to “numeric”

sliderTxtFld.inputType = “number”.

 

 

However when i try this on android i get the keyboard with the numbers BUT without the decimal point button.

 

when i set the input type to “number|numberDecimal” or “decimal” or “text” i get the standard keyboard which i can

enter the decimal BUT the letters are also present, this means i will have to test for key presses and stop any non

numeric key preses.

 

i also tried “phone” setting and this gives a phone pad (with a decimal key) but it also gives some other non

numeric keys which again would have to be checked for.

 

From the various forums i see this has been an issue for many years and was wondering if anybody had fixed this

simple issue, as i am sure there are plenty of Apps that want to enter decimal numbers out there.

 

regards

bruce

 

The best advice is to use the “phone” keyboard. 

Rob

ok Rob thanks fot that, that was the conclusion i was coming to as well, But using phone keyboard also allows the user to enter non-numeric characters.  Then we need to check the keypress events and disallow certain keys.

Is there some Lua, Corona code already written like the Regex code to only allow 0…9 and decimal point be it ‘.’ or ‘,’ depending on localisation?

Bruce

For each key entered, you will get an “editing” event.phase. You can easily strip the invalid characters using the string.gsub() function. Here’s a quick example:

local s = "abc 123 george 987,654.321 jetson 999 , . ." local newS = "" for val in s:gmatch("([%d%p]+)") do print(val) newS = newS .. val end print(newS)

results in newS = 123987,654.321999,…  

You could refine the pattern matching a little further by using ([%d%.%,]+)  and just update the .text value of the field as you get an editing phase.

Rob

Rob

thanks, that looks like it will work for now.  i actually found a piece of code for an onScreenKeyboard, already written in Lua. to display letter, number or symbol keyboards.  It needed a little refining as it was written for Graphics V1 and a few references had changed going to Graphics V2.

Plus my app code needs some re-tuning before i can fully implement the onScreenKeyboard.  But the onScreenKeyboard looks to be the way to go once i get some time to fix my code.

Regards

Bruce

Rob

further to this issue about number pad on android devices, i recently download an app called “tank volume” by Sotnikov onto by android phone.  Now this app has a number pad with a decimal point and a next / done button (as it has 4 inputs) so you can “next” down the list then hit done after the last input.

This keyboard is exactly what i need, so looking at this App there must be some setting in android world that allows for decimal number inputs and not just integer numbers and phone numbers.

i don’t know if you can help or not but it seems a bit of a stretch that android does not handle decimal numbers better than we have discussed in this thread.

Regards

Bruce

Hi Bruce,

For the “next down the list” did you try this method?

https://docs.coronalabs.com/api/type/TextField/setReturnKey.html

It should allow you to change the appearance of the “return” key as users move from one to the next.

Brent

If you use the tonumber() for the resulting string I think you don’t need to do anything else. The only thing is when the Android user call the keyboard he need to press the “123” to see the keyboard numbers. Or you can make your own 12 buttons an simulate an on screen numeric keypad.

Cheers

thanks for the feedback,

Currently i am using the phonepad option on android, along with the string pattern matching during the event “editing” phase. to make sure i get a number entered.  i also have code to make my own onscreen keyboard, which may be the ultimate solution (unless android modifies their system to support decimal numbers).  how ever as mention above i saw an App “Tank Volume” that has a decimal keypad that looks exactly like like the android keypad, now i don’t know if the App uses a custom keyboard or a built in android keyboard.  Either way there does exist an exact keyboard (decimal number keypad) that i want to use in my app.

Is this something that could be added to Corona?

We are looking into adding the decimal keyboard on Android since we have it on iOS.

Rob

Rob

i got the new version (3135) and the “decimal” keypad is called using my App.  all works fine until i try to press the decimal key and then it refuses to accept the decimal point.  Ahhhh…

i thought this was going to be it, so it is a bit frustrating that i cannot enter a number like 12.25 on the “decimal” pad.  i can use the “phone” pad and it worked as we discussed above.

has any one else seen this error on the “decimal” keyboard on android.

Bruce

What device are you testing on?

Rob

Rob

i am testing on a Samsung Note 3 phone. i even editted out the editing phase just in case that was doing something funny but the decimal keypad just would not allow me to enter the decimal point.

the keypad was on the screen and was perfect, showing numbers and decimal point and Done button all as you would expect but i just cannot use the decimal button no matter how many time i press it.

my whole app is designed around using decimal numbers hence my need for decimal input.

bruce

What version of Android is it running?

Thanks

Rob

Most likely it is Samsung issue. They have always had problems with decimal keypad. Have you had a chance to test it on another device?

It works fine on my Asus ZenFone… just tested.

Brent

Guys

ok, my Samsung is running android 4.3.  so it might be a Samsung device issue.  that makes things harder as I will have to take care about which device and android version is running when I set the input type for my keyboard.

which version android is Asus Zen running >4.3?

Bruce

guys

just a follow up on this decimal key issue, I have a few other Apps from other people that use the decimal key pad and the decimal key works on my Samsung Note 3, so I don’t think the issues is down to that now.

I also had a closer look at my App and the other Apps on my Note 3 and it looks like the decimal key in my App is disabled whereas on the other Apps I have the key looks to be enabled, by that I mean using my app the key looks a little dimmed compared to the more brighter keys on the other apps.  It is difficult to tell for sure as the key only displays a “.” so detecting if it is brighter or not is not so easy but it sure looks like the key is disabled.  The Apps I have that use the decimal keypad are Tank Volume by Sotnikov and Well Handbook by ofsapps.com.

Regards

Bruce

Maybe this is relevant?   https://ultimatevaluediary.freshdesk.com/support/solutions/articles/5000535726-android-no-decimal-point-on-samsung-galaxy-device

Rob

Rob

ok thanks for that, I will have to think again then, what I set my App to run at for Android phones/devices, most likely I will have to set the input type to “phone” to make sure everybody can get access to the decimal key.

Bruce.