iOS Question B4X Dialog - position and float number

kompiler

Member
Licensed User
Hi, I have two questions.

1. How can I change the position of B4X Dialog on the screen? Dialog is too high and is under the Notch.

2. How can I enter the floating point number correctly? When I type the dot, then I can't confirm.

B4X:
InputTemplate.ConfigureForNumbers(True,False)

0.jpg
 

emexes

Expert
Licensed User
If the Android region is set correctly and the Java/B4A String-To-Int/Float/Double casting doesn't use "," as the decimal point, then the simplest solution might be to fix it yourself, eg:
B4X:
Dim UnitPrice As Double = PriceEdit.Text.Replace(",", ".")
which has the happy effect of NOT changing existing "." and thus will work regardless of whether "." or "," is used as the decimal point :)
 
Upvote 0

kompiler

Member
Licensed User
This is the code, I have no way for Replace(",",".")

B4X:
Sub Label1_Click
    InputTemplate.lblTitle.Text="test"
    InputTemplate.ConfigureForNumbers(True,False)
    Dialog1.Title="test"
    Wait For (Dialog1.ShowTemplate(InputTemplate,"OK","","Cancel")) Complete (Result As Int)
    If Result=XUI.DialogResponse_Positive Then   
        Log(InputTemplate.Text)
    End If
End Sub
 
Upvote 0

emexes

Expert
Licensed User
This is the code, I have no way for Replace(",",".")
Ye of little faith...
B4X:
If Result=XUI.DialogResponse_Positive Then
    Dim NumberString As String = InputTemplate.Text.Trim.Replace(",", ".")    'convert "," decimal point to "." (also slipped in a .Trim, to be sure, to be sure ;-)
    If IsNumber(NumberString) Then    'check that it looks like a number
        Dim HappyWithThat As Float = NumberString    'converts from string to number
        Log("I can understand that number, eg, multiplied by two it is " & NumberFormat2(HappyWithThat * 2, 1, 0, 2, False))
    Else
        Log("I don't understand that number.")
    End If
End If
 
Upvote 0

emexes

Expert
Licensed User
Hey, what happened with your Apple Bottles? I thought we'd fixed that so that it encompassed/filled the whole screen.

Out of interest, what happens if you double the size of that ImageView, after loading the layout and ideally before the image is loaded into it, eg:
B4X:
Activity.LoadLayout("Layout1")

Dim FitFactor As Float = 2
'''FitFactor = Max(100%x / AppleBottleImage.Width, 100%y / AppleBottleImage.Height)    'try this after trying 2

Log("Scaling bottles by " & FitFactor)

AppleBottleImage.Width = AppleBottleImage.Width * FitFactor
AppleBottleImage.Height = AppleBottleImage.Height * FitFactor
 
Upvote 0

kompiler

Member
Licensed User
B4X:
If Result=XUI.DialogResponse_Positive Then
    Dim NumberString As String = InputTemplate.Text.Trim.Replace(",", ".")
I can't change the values because I can't confirm them.

The image is displayed correctly, thank you for the question.
 
Upvote 0

emexes

Expert
Licensed User
I can't change the values because I can't confirm them.
Took me a while to work out what "can't confirm them" meant, but now I understand: if the entered field text is not a number, then the OK button is disabled.

The problem is still likely that the "," is not accepted by IsNumber as a decimal point. So, two things to try are:

1/ temporarily set your localisation to something that uses "." as a decimal point, see if that changes the keypad "," to a "."
2/ with localisation set back to your region and using "," as a decimal point, see what IsNumber("123,45") and IsNumber("123.45") return

It might be possible to hook into the EditText that is part of the dialog and convert "," to ".", but... it'd be far better if the number verification accepted the local decimal point character.

In the meantime, perhaps you can use a text input but with the numeric keypad. Yeah, your users will then be able to confirm/Ok invalid numbers, like with two decimal points/commas, etc, but you can catch that by fixing/checking the returned value with .Replace(",", ".") / IsNumber().

What could possibly go wrong?!?!?!

Looking forward to the results of checks 1/ and 2/.
 
Upvote 0

kompiler

Member
Licensed User
Yes, the problem is the region and language, but I want to set the correct region and language.
Are there other Dialog that will allow me to enter a floating point number correctly?

0.jpg


Now it works with a full keyboard.

B4X:
'InputTemplate.ConfigureForNumbers(False,False) <- without numbers

If InputTemplate.Text.Length>0 Then
If IsNumber(InputTemplate.Text) then
..

There is still a problem with Dialog position.
 
Last edited:
Upvote 0

emexes

Expert
Licensed User
Lazybones here was testing it in B4J, rather than fire up an Android phone.

I assume if you comment out the .ConfigureForNumbers line, that it will default to text entry, and display a full keyboard.

The longer-term solution is for the dialog to use/accept the regional numeric punctuation (or whatever the official term is). The keypad appears to already be doing that (eg, it has a comma). But before making that request to the developer of that class, you should delineate the problem as best you can, eg, does the Java/B4A IsNumber have the same issue? It might be that the dialog box is not using IsNumber, and that the rule is that the input number text can either contain NO decimal point/comma, or ONE decimal point/comma with a digit on each side.
 
Upvote 0

kompiler

Member
Licensed User
For instructions
B4X:
InputTemplate.ConfigureForNumbers (True, False)
the keyboard allows me to type many ","

0.jpg


Below is a screenshot for the instructions for IsNumber

1.jpg


I can only use the full keyboard at the moment, without ConfigureForNumbers.
 
Upvote 0

emexes

Expert
Licensed User
Having read up a bit more about it, it seems that IsNumber (and thus the conversion of strings to numbers) is firmly wedded to the decimal point being a "."

But the numeric keypad presents either "." or "," depending on the localisation setting.

You will never get core B4A/Java changed to recognize "," as a decimal point; this is something you have to workaround yourself (with ye olde .Replace(",", "."))

So your current problem is that the B4XDialog .ConfigureForNumbers validity checker is not accepting the decimal point character made available on the numeric keypad.


The solutions are either:

1/ the keypad be made to only have "." for decimal point, ie, ignore localisation, or

2/ the .ConfigureForNumbers validity checker be made to accept whichever decimal point character is offered by the numeric keypad


Are you able to select or change the keypad that is brought up, so that it has a "." instead of a "," for the decimal point?

If not, then 2/ is the only cure.
 
Upvote 0

kompiler

Member
Licensed User
I have no choice on the numeric keypad and only the full keyboard without ConfigureForNumbers can help. Thank you for all the answers.
 
Upvote 0

emexes

Expert
Licensed User
I have no choice on the numeric keypad and only the full keyboard without ConfigureForNumbers can help. Thank you for all the answers.
No worries. Keep in mind the "," to "." / checking / conversion code from post #4, to stop random user entry from crashing your app.

:)
 
Upvote 0
Top