Android Question Dialog/template after Msgbox2Async = no keyboard?

RJB

Active Member
Licensed User
Hi,
With the following(example) code the first time the 'Wait For (NameDialog.ShowTemplate(Help, "OK", "", "CANCEL")) Complete (Result As Int)' line (28) is run no keyboard is shown, after that it shows.
It is shown if the 'Wait For Msgbox_Result (Result As Int)' line (9) is commented and a 'Msgbox_Result' sub used or if the 'Sleep(0)' line (19) is uncommented.

I can use the sleep(0) option but was just interested as to why it fails


B4X:
    Dim newname As String = "a name"
       
    Msgbox2Async(newname & " exists, do you want to replace it?", "Existing Layout", _
                    "Yes", _
                    "Cancel", _
                    "No", _
                    Null, _
                    True)
    Wait For Msgbox_Result (Result As Int)
    Select Case Result
        Case DialogResponse.POSITIVE
'...
        Case DialogResponse.NEGATIVE
'...
        Case DialogResponse.CANCEL
'...
    End Select

'Sleep(0)
    Dim NameDialog As B4XDialog
    NameDialog.Initialize(Activity)
    NameDialog.Title = "Please enter a name"
    Dim Help As B4XInputTemplate
    Help.Initialize
    Help.lblTitle.Text = "   Use something descriptive!"
    Help.RegexPattern = ".+" 'require at least one character
    Do While True
        Wait For (NameDialog.ShowTemplate(Help, "OK", "", "CANCEL")) Complete (Result As Int)
    Loop
 

agraham

Expert
Licensed User
Apparently you want to show a dialog and then another after the first returns. Your whole structure looks wrong to me - remember that a Wait For is equivalent to a return so it will run into the second dialog call as you wait for the first. Also looping for a Wait For is unnecessary and wrong.

I would put each dialog into its own Resumable Sub and call and wait for them in turn from a third Sub.
 
Upvote 0

RJB

Active Member
Licensed User
Hi,
It is only an Example to show the problem.
However the logic does work, i.e. the first 'wait for' waits and the second dialog runs only after the Msgbox2Async completes.
The looping is only to show that the keyboard appears on subsequent 'NameDialog.ShowTemplate' calls. It is only called once in the real code.
As I said I would be interested to know why it fails - so that I can avoid problems in the future.
 
Upvote 0
Top