Wish View for numeric input only (integers and decimals) with management of culture by country

gdeppi

Member
Licensed User
Longtime User
In the perspective of continuous improvement I would like to ask for a
implementation of a specialized view for numeric input only (integers and decimals)
with the management of the culture by country (for example for Italy 1.234,00) and
with the correct recognition of the comma or point for the decimal separator according
to the culture and also the correct recognition of the thousands separator, always
according to the culture.

Best regards.
 

gdeppi

Member
Licensed User
Longtime User
Yes, it is, but an EditText with that feature would greatly facilitate.

It is obviously possible to make a wrapper library of the EditText.

Obviously this was the spirit of my request, then everything can be done ...

But I do not understand why other development environments have these specialized components, while here there are not ...
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Complete example:
SS-2017-12-14_16.21.59.png


B4X:
Sub Process_Globals
   Private ahnumeric As AHNumeric
End Sub

Sub Globals
   Private ime As IME
   Private EditText1 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
   If FirstTime Then
       Dim locale As AHLocale
       'locale.Initialize 'device default locale
       locale.Initialize2("it") 'italic locale
       ahnumeric.Initialize2(locale)
   End If
   Activity.LoadLayout("1")
   ime.Initialize("ime")
   ime.SetCustomFilter(EditText1, EditText1.INPUT_TYPE_DECIMAL_NUMBERS, "01234567890,.")
   SetNumberToEditText(EditText1, 1000000.333)
End Sub

Sub GetNumberFromEditText(et As EditText) As Double
   Return ahnumeric.Parse(et.Text)
End Sub

Sub SetNumberToEditText(et As EditText, d As Double)
   et.Text = ahnumeric.Format(d)
End Sub

Sub Button1_Click
   Dim d As Double = GetNumberFromEditText(EditText1)
   Log(d)   
End Sub
There is always a risk with custom filters that the installed keyboard will not respect this property. There isn't much that you can do about it except of creating your own keyboard.
Custom numpad: https://www.b4x.com/android/forum/threads/customview-numpad.64191/#content
 
Top