Android Question b4xDialog / design class

FrankDev

Active Member
Licensed User
Longtime User
Hello,

i am trying to make class to outsource the designing at the
b4xdialogs.

The current options to customize these are great, but too much overhead when calling.

I want to call a msgbox with only one line. With a class I can use the design also for other projects without problems.

With the call, that works already. Unfortunately I am not sure how to return the result (true / false ) to the calling activity.

maybe someone can help me to do the whole thing 'right'.

regards
Frank

Translated with www.DeepL.com/Translator
 

Attachments

  • myB4Xmsgbox.zip
    11 KB · Views: 104

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
It is not possible to do in 1 line, but I can do it in 2 lines.

Here is one way to do it.

You need to wait for a call

The key part is as follows:

In main,
B4X:
    ' added callback object
    Dialog.ShowCustom2(Me,"title text", "content text", "yes","no")
    'wait for the event to be called
    wait for mydialog_complete(result As Int)

    Log($"Result Is ${result}"$)

in your special class

B4X:
  Wait For (sf) complete (result As Int)
    
    'call the callback with the event and result
    CallSubDelayed2(callback,eventname&"_complete",result)

At the moment the class returns either xui.DialogResponse_Positive or xui.DialogResponse_negative.
 

Attachments

  • b4xdialogclassdesign.zip
    11.5 KB · Views: 103
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
or you could do it this way...


in Main
B4X:
    wait for (Dialog.ShowCustom2("title text", "content text", "yes","no")) complete (result As Int)

    Log($"Result Is ${result}"$)

in myB4xMsgBox
B4X:
Public Sub ShowCustom2( title As String, Cont As String, btnYes As String, btnno As String) As ResumableSub
    
    
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 300dip, 350dip)
    p.LoadLayout("CustomDialog")
    lblTitle.Text = title
    lblContent.text = Cont
    Button1.Text = btnYes
    Button2.Text = btnno
    dlg.PutAtTop = True
    Dim sf As Object = dlg.ShowCustom(p, "", "", "")
    dlg.Base.top = (100%y /2) - (dlg.Base.Height /2)
    p.Height = dlg.Base.Height
    
    
    Wait For (sf) complete (result As Int)
    Return result
End Sub



Private Sub Button1_Click
    'how To close the dialog
    'And with 'reply' back to the calling activity
    
    'close the dialog
    dlg.Close(xui.DialogResponse_Positive)
End Sub

Private Sub Button2_Click
    'how To close the dialog
    'And with 'reply' back to the calling activity
    
    'close the dialog
    dlg.Close(xui.DialogResponse_negative)
End Sub

which is I think what you were looking for.
 
Upvote 0
Top