Android Question B4XDialog as a custom class

Sergey_New

Well-Known Member
Licensed User
Longtime User
Created class MyDlg with B4XDialog.
I would like to use it in several Activities. Tell me how to return the Result value from this class?
An example is attached.
 

Attachments

  • MyDialog.zip
    8.6 KB · Views: 82
Solution
Not tested
B4X:
Sub Button1_Click
    Dim dlg As MyDlg
    dlg.Initialize(Activity)
    Dim rs As ResumableSub
    rs = dlg.Show("Title","Message","Ok","Cancel","No",LoadBitmap(File.DirAssets, "warning.png"))
    Wait For (rs) Complete (Result As Int)
    Select Result
        Case XUI.DialogResponse_Cancel
            Log(Result)
        Case XUI.DialogResponse_Negative
            Log(Result)
        Case XUI.DialogResponse_Positive
            Log(Result)
    End Select
End Sub
B4X:
Sub Class_Globals
    Private xui As XUI
    Private Dialog As B4XDialog
    Private lbMess As Label
    Private lbTitle As Label
    Private img As ImageView
    Private rs As ResumableSub
End Sub

Public Sub Initialize(act As Activity)...

TILogistic

Expert
Licensed User
Longtime User
Not tested
B4X:
Sub Button1_Click
    Dim dlg As MyDlg
    dlg.Initialize(Activity)
    Dim rs As ResumableSub
    rs = dlg.Show("Title","Message","Ok","Cancel","No",LoadBitmap(File.DirAssets, "warning.png"))
    Wait For (rs) Complete (Result As Int)
    Select Result
        Case XUI.DialogResponse_Cancel
            Log(Result)
        Case XUI.DialogResponse_Negative
            Log(Result)
        Case XUI.DialogResponse_Positive
            Log(Result)
    End Select
End Sub
B4X:
Sub Class_Globals
    Private xui As XUI
    Private Dialog As B4XDialog
    Private lbMess As Label
    Private lbTitle As Label
    Private img As ImageView
    Private rs As ResumableSub
End Sub

Public Sub Initialize(act As Activity)
    Dialog.Initialize(act)
End Sub

Sub Show(title As String,message As String,Ok As String,Cancel As String,No As String, icon As Bitmap) As ResumableSub
    Dim x As B4XView = xui.CreatePanel("")
    x.SetLayoutAnimated(0, 0, 0, 340dip, 25%y)
    x.LoadLayout("dlgdetail")
    Dialog.PutAtTop = True
    Dialog.BorderWidth = 2dip
    Dialog.BorderCornersRadius = 6dip
    Dialog.BorderColor = Colors.Blue
    Dialog.BackgroundColor = Colors.LightGray
    Dialog.OverlayColor = 0x80808080
    lbTitle.Padding=Array As Int (img.Width+4dip, 0dip, 0dip, 0dip)
    lbTitle.Text=title
    lbMess.Text=message
    img.Bitmap=icon
    rs = Dialog.ShowCustom(x, Ok, No, Cancel)
    Wait For (rs) Complete (Result As Int)
    Return Result
End Sub
 
Upvote 0
Solution

Sergey_New

Well-Known Member
Licensed User
Longtime User
TILogistics, thank you!
I checked - Need to add to the calling Activity
B4X:
Private xui As XUI
Or do this:
B4X:
Sub Button1_Click
    Dim dlg As MyDlg
    dlg.Initialize(Activity)
    Dim rs As ResumableSub
    rs = dlg.Show("Title","Message","Ok","Cancel","No",LoadBitmap(File.DirAssets, "warning.png"))
    Wait For (rs) Complete (Result As Int)
    Select Result
        Case -3
            Log(Result)
        Case -2
            Log(Result)
        Case -1
            Log(Result)
    End Select
End Sub
 
Upvote 0
Top