Android Question Reissue a Custom B4XDialog

bocker77

Active Member
Licensed User
Longtime User
I am trying to reissue a custom dialog if the user does not fill in all of the options but on the second time around it blows past the wait and goes to the line where database gets initialized. After doing some reading I tried the dialog close and setting the response to null but cannot get it to work. Does anyone have any suggestions?

Code: Copy
Sub NewGame    
    Dialog.PutAtTop = True
    Dialog.Title = csMsgTitle
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 451dip, 440dip)
    p.LoadLayout("GameType")
    Dim rsp As ResumableSub = Dialog.ShowCustom(p, "Done", "", "")
    Log(rsp.Completed)
    Dim btnDone As B4XView = Dialog.GetButton(xui.DialogResponse_Positive)
    btnDone.SetBitmap(bmpBtnUp)
    AnimateDialog(Dialog, "bottom")
    Wait For (rsp) Complete (Result As Int)
    Log(rsp.Completed)
    If Result = xui.DialogResponse_Positive Then
        Log("Army: " & strArmy & ", Size: " & strSize & ", Type: " & strType)
        If strArmy = "" Or strSize = "" Or strType = "" Then
            Dialog.Close(xui.DialogResponse_Positive)
            Dialog.Close(xui.DialogResponse_Negative)
            Dialog.Close(xui.DialogResponse_Cancel)
            Dialog.Close(Result)
            rsp = Null
            SendMsg(Error, "Not all options have been selected")
            NewGame
        End If
    End If
    ' Initalize Database
    sqlGameDB.Initialize(strGamesPath, strGameName, True)
 
Try putting a Sleep(100) before displaying it a second time (same for two different dialogs in succession). I seem to remember 100 worked, but you may have to make it a little longer. Although in the code you posted, I can't see where it is called for a second time.
 
Upvote 0
It is reissued by calling the NewGame sub again. If there is a better way of doing it let me know. Also I am assuming that I do not need these lines.

Code: Copy
            Dialog.Close(xui.DialogResponse_Positive)
            Dialog.Close(xui.DialogResponse_Negative)
            Dialog.Close(xui.DialogResponse_Cancel)
            Dialog.Close(Result)
 
Upvote 0
The sleep with 100 and 1000 values does not work. I placed it right before the call to the sub routine.
 
Upvote 0
On B4j, I usually do it like this:

B4X: Copy
    Do While True
        Dialog.Title = "Loop Test"
        Dim P As B4XView = xui.CreatePanel("")
        P.SetLayoutAnimated(0,0dip,0dip,300dip,300dip)
        P.LoadLayout("dlg")
       
        Dim RS As ResumableSub = Dialog.ShowCustom(P,"OK","","Cancel")
       
        Wait For (RS) Complete (Resp As Int)
        If P.GetView(1).Text.ToLowerCase = "exit" Or Resp = xui.DialogResponse_Cancel Then Exit
       
        Sleep(100)
    Loop

Just tested on B4a and it works the same, even without the Sleep(100).
The layout holds a label and a TextField which is why it is testing P.GetView(1).
 
Upvote 0
Back
Top