1. *** New version of B4J is available ***
    B4J v7.8
    Dismiss Notice

iOS Question B4X Dialog - position and float number

Discussion in 'iOS Questions' started by kompiler, Sep 13, 2019 at 6:33 PM.

  1. kompiler

    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.

    Code:
    InputTemplate.ConfigureForNumbers(True,False)
    0.jpg
     
  2. emexes

    emexes Well-Known Member 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:
    Code:
    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 :)
     
    kompiler likes this.
  3. kompiler

    kompiler Member Licensed User

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

    Code:
    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
     
  4. emexes

    emexes Well-Known Member Licensed User

    Ye of little faith...
    Code:
    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 * 2102False))
        
    Else
            
    Log("I don't understand that number.")
        
    End If
    End If
     
    kompiler likes this.
  5. emexes

    emexes Well-Known Member 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:
    Code:
    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
     
    kompiler likes this.
  6. kompiler

    kompiler Member Licensed User

    Code:
    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.
     
  7. emexes

    emexes Well-Known Member Licensed User

    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/.
     
    kompiler likes this.
  8. kompiler

    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.

    Code:
    '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: Sep 14, 2019 at 3:31 PM
  9. emexes

    emexes Well-Known Member 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.
     
  10. kompiler

    kompiler Member Licensed User

    For instructions
    Code:
    InputTemplate.ConfigureForNumbers (TrueFalse)
    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.
     
  11. emexes

    emexes Well-Known Member 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.
     
    kompiler likes this.
  12. kompiler

    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.
     
    emexes likes this.
  13. emexes

    emexes Well-Known Member Licensed User

    No worries. Keep in mind the "," to "." / checking / conversion code from post #4, to stop random user entry from crashing your app.

    :)
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice