I have the following code that uses a B4XTable to 'load' NUMERIC values in some columns:
B4X:
'Proceso la carga...
If column.Id = "Energía" Or column.Id = "Agua" Then
InputTemplate.Text = value
InputTemplate.lblTitle.Text = column.Id
Wait For (Dialog.ShowTemplate(InputTemplate, "Aceptar", "", "Cancelar")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
This code shows on screen a data entry dialog and the 'Full keyboard' ... so if you enter 'letters' it produces an error when recording the information as it expects them to be numbers.
Query:
1) How can I activate ONLY the numeric keypad?
2) or how you can 'control that Result is ONLY a numerical value and otherwise ... put ZERO or ask again
I don't know about q1 (although the ide tips-as-you-type auto-help might reveal an InputTemplate property to select the keyboard type).
For q2, you can use IsNumber to check whether a string can be cast/parsed to a number (well, a double - so watch out for large values):
so perhaps something like:
B4X:
Do While True
InputTemplate.Text = value
InputTemplate.lblTitle.Text = column.Id
Wait For (Dialog.ShowTemplate(InputTemplate, "Aceptar", "", "Cancelar")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
If IsNumber(InputTemplate.Text) Then
Exit 'Do Loop
End If
End If
Loop
which, if the user enters an invalid number, will reset the initial/default entry to value and ask 'em again. I'm not sure what should happen if the user chooses Cancelar, so I've left that for you to think about ;-)
Thanks for your help!. Someone passed me a property that directly disables letters and ONLY allows positive numbers:
B4X:
If column.Id = "Energía" Or column.Id = "Agua" Then
InputTemplate.Text = value
InputTemplate.lblTitle.Text = column.Id
InputTemplate.ConfigureForNumbers(False, False) 'AllowDecimals, AllowNegative (Decimales,Negativos) '<<<<<<<<
Wait For (Dialog.ShowTemplate(InputTemplate, "Aceptar", "", "Cancelar")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then