Android Question Panel for B4XDialog visible must be set manually

Dear all,
I found today the visible of panel for B4XDialog must be set manually. Otherwise, the dialog would not be shown.

panel dialog:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private btn1 As Button
    Private Dialog As B4XDialog
    Private pnlDialog As B4XView
    Private pnlButton As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    If pnlButton.IsInitialized = False Then
        pnlButton = xui.CreatePanel("")
        pnlButton.Color = Colors.Blue               
        btn1.Initialize("btn1")       
        btn1.TextColor = Colors.White
        btn1.Text = "Dialog"
        pnlButton.AddView(btn1, 10dip, 10dip, 300dip, 100dip)
        Activity.AddView(pnlButton, 0, 0, Activity.Width, Activity.Height)
    End If
    If pnlDialog.IsInitialized = False Then
        pnlDialog = xui.CreatePanel("")
        pnlDialog.Color = Colors.White
        pnlDialog.Visible = False '<-- must be invisible for dialog panel after initialized
        Activity.AddView(pnlDialog, 0, 0, Activity.Width, Activity.Height)
    End If
End Sub

Sub btn1_Click
    If Dialog.IsInitialized = False Then
        Dialog.Initialize(pnlDialog)
    End If
    pnlDialog.Visible = True '<-- must be visible if active
    Dim LT As B4XListTemplate
    LT.Initialize
    LT.Options.AddAll(Array As String("Item 1","Item 2","Item 3"))
    LT.Resize(LT.mBase.Width,LT.mBase.Height - 100)
    Dialog.Title = "Choose"
    Wait For(Dialog.ShowTemplate(LT,"","","Cancel")) Complete (Resp As Int)
    pnlDialog.Visible = False '<-- must be invisible if inactive
    Log(LT.SelectedItem)
End Sub

I found it is an inconvenience for novice. Is it possible to automatically open the dialog on demand?
 
When replacing by Dialog.Initialize(Me) on line #38, the error occurred as:

error log:
Error occurred on line: 95 (B4XDialog)
java.lang.ClassCastException: java.lang.Class cannot be cast to android.view.View
    at anywheresoftware.b4a.objects.B4XViewWrapper.getViewObject(B4XViewWrapper.java:102)
    at anywheresoftware.b4a.objects.B4XViewWrapper.asPanelWrapper(B4XViewWrapper.java:105)
    at anywheresoftware.b4a.objects.B4XViewWrapper.GetAllViewsRecursive(B4XViewWrapper.java:305)
    at b4a.example.b4xdialog$ResumableSub_ShowCustom.resume(b4xdialog.java:215)
    at b4a.example.b4xdialog._showcustom(b4xdialog.java:150)
    at b4a.example.b4xdialog$ResumableSub_ShowTemplate.resume(b4xdialog.java:906)
    at b4a.example.b4xdialog._showtemplate(b4xdialog.java:863)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:732)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:351)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:255)
    at java.lang.reflect.Method.invoke(Native Method)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:144)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:197)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:193)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:5265)
    at android.view.View$PerformClick.run(View.java:21534)
    at android.os.Handler.handleCallback(Handler.java:815)
    at android.os.Handler.dispatchMessage(Handler.java:104)
    at android.os.Looper.loop(Looper.java:207)
    at android.app.ActivityThread.main(ActivityThread.java:5765)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:789)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:679)
** Service (starter) Destroy (ignored)**

Thus, a dialog panel pnlDialog is required for display.
 
Upvote 0
Thanks Erel, replace panel by activity works!

panel replaced by activity:
Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'These variables can be accessed from all modules.
    Private xui As XUI
End Sub

Sub Globals
    'These global variables will be redeclared each time the activity is created.
    'These variables can only be accessed from this module.
    Private btn1 As Button
    Private Dialog As B4XDialog
    'Private pnlDialog As B4XView
    Private pnlButton As B4XView
End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    'Activity.LoadLayout("Layout1")
    If pnlButton.IsInitialized = False Then
        pnlButton = xui.CreatePanel("")
        pnlButton.Color = Colors.Blue               
        btn1.Initialize("btn1")       
        btn1.TextColor = Colors.White
        btn1.Text = "Dialog"
        pnlButton.AddView(btn1, 10dip, 10dip, 300dip, 100dip)
        Activity.AddView(pnlButton, 0, 0, Activity.Width, Activity.Height)
    End If
    'If pnlDialog.IsInitialized = False Then
    ''    pnlDialog = xui.CreatePanel("")
    ''    pnlDialog.Color = Colors.White
    ''    pnlDialog.Visible = False '<-- must be invisible for dialog panel after initialized
    ''    Activity.AddView(pnlDialog, 0, 0, Activity.Width, Activity.Height)
    'End If
End Sub

Sub btn1_Click
    If Dialog.IsInitialized = False Then
        'Dialog.Initialize(pnlDialog)
        Dialog.Initialize(Activity)
    End If
    'pnlDialog.Visible = True '<-- must be visible if active
    Dim LT As B4XListTemplate
    LT.Initialize
    LT.Options.AddAll(Array As String("Item 1","Item 2","Item 3"))
    LT.Resize(LT.mBase.Width,LT.mBase.Height - 100)
    Dialog.Title = "Choose"
    Wait For(Dialog.ShowTemplate(LT,"","","Cancel")) Complete (Resp As Int)
    'pnlDialog.Visible = False '<-- must be invisible if inactive
    Log(LT.SelectedItem)
End Sub
 
Upvote 0
Top