Android Question [Solved] How to change Msgbox2 to Msgbox2Async in this code

asales

Expert
Licensed User
Longtime User
I use this code to - with a long click - remove the click panel:
B4X:
Sub pnl_LongClick
    Dim result As Int
    result = Msgbox2("Confirm?", "Remove panel", "Yes", "", "No", Null)
    If result <> DialogResponse.Positive Then Return

    Dim pn As Panel = Sender
    pn.RemoveView
End Sub

but If I changed to Msgbox2Async:
B4X:
Sub pnl_LongClick
    Msgbox2Async("Confirm?", "Remove panel", "Yes", "", "No", Null, False)
    Wait For Msgbox_Result (Result As Int)
    If Result <> DialogResponse.POSITIVE Then Return

    Dim pn As Panel = Sender
    pn.RemoveView
End Sub

I get this error:
B4X:
chat$ResumableSub_pnl_LongClickresume (java line: 330)
java.lang.ClassCastException: android.app.AlertDialog cannot be cast to android.view.ViewGroup
at b4a.example.chat$ResumableSub_pnl_LongClick.resume(chat.java:330)
How I can fix it?

Thanks in advance for any tip.
 

DonManfred

Expert
Licensed User
Longtime User
How I can fix it?
after the dialog shown the SENDER has changed

I suggest to get the panel ref before showing the dialog.

B4X:
Sub pnl_LongClick
    Dim pn As Panel = Sender
    Msgbox2Async("Confirm?", "Remove panel", "Yes", "", "No", Null, False)
    Wait For Msgbox_Result (Result As Int)
    If Result <> DialogResponse.POSITIVE Then Return

    pn.RemoveView
End Sub
 
Upvote 0
Top