Android Question Is it possible to open a second dialog from within a custom dialog? (Nested B4XDialogs)

PhiloSophical

Member
Licensed User
Longtime User
I can't seem to find a way to do this - using b4xpages I can set the second sub-dialog parent to "root" but on the close of the dialog the custom dialogue also closes.

I am trying to put a calendar popup on a custom dialogue form. Not sure how to initialize it using the custom dialogue as the parent. Am I trying the impossible?

Thanks
 

PhiloSophical

Member
Licensed User
Longtime User
Thanks for the encouragement @agraham - I re-wrote some code and solved my problem by initializing the sub dialog as parent.base. I did think I'd tried that but must have been half asleep and muddled something else that lead to a "not initialized error" - it is Friday afternoon after all! Thanks for helping.

B4X:
'solution
Dim d2 As B4XDialog
d2.Initialize(d1.Base)
 
Last edited:
Upvote 0

PhiloSophical

Member
Licensed User
Longtime User
Thanks @Erel for your example. I tried modifying it so that I initialised the nested dialog using main.dialog(seconddialog.base) but AFTER the main dialog was showing. This worked fine and I think might be more intuitive than remembering to clear the tag with your code suggestion. I'll amend this post if I've overlooked something.

The back key handling in your example is very helpful too!

code mods shown:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("1")
    MainDialog.Initialize(Root)
    'removed
    'SecondDialog.Initialize(root)
    MainDialog.Title = "Example"
    CustomPanel = xui.CreatePanel("")
    CustomPanel.SetLayoutAnimated(0, 0, 0, 300dip, 300dip)
    CustomPanel.LoadLayout("CustomLayout")
End Sub

Sub btnShowDialog_Click
    Dim rs As Object = MainDialog.ShowCustom(CustomPanel, "Ok", "", "")
    Log(MainDialog.Base.Parent.Tag) 'produces "b4xdialog_background"
    'removed
    'MainDialog.Base.Parent.Tag = "" 'this will prevent the dialog from closing when the second dialog appears.
    Wait For (rs) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        
    End If
End Sub

Sub DialogButton_Click
    Dim Btn As B4XView = Sender
    'inserted
    SecondDialog.Initialize(MainDialog.Base)
    Wait For (SecondDialog.Show("Delete button?", "Yes", "No", "")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        Btn.RemoveViewFromParent
    End If
End Sub
 
Upvote 0
Top