Android Question B4X Custom Dialogue - Modifying & Returning A Value

RichardN

Well-Known Member
Licensed User
Longtime User
I am sure there is something fundamental I am missing here....

I wish to send a value to a B4X Custom Dialogue as a default value, display the dialogue and allow the user to modify it, then perform a calculation with the result. Unfortunately the example code uses 'Wait For' so can only return a Resumeable Sub. In the code below the Log() reports 'I'm Back' before the user has modified anything. I have tried using a Global variable within the Dialoge code but it returns before user input occurs with an incorrect value. I have tried putting the 'Calculate' Sub within the 'If Result = xui.DialogResponse_Positive' but it appears to be return zero all the time.

I wish to use this Dialogue to modify several different values in the app. What is the correct technique to use?

Hours & Minutes to minutes:
Sub btnStartTime_Click
    
    ShowHoursDialog("Enter Start Time",StartTime)
    Log("I'm Back")
    CalculateResult
    
End Sub

Sub ShowHoursDialog(Prompt As String, Default As Int)
    
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 250dip, 150dip) 'set the content size
    p.LoadLayout("dialog")
    Dialog.Title = Prompt
    Dialog.BlurBackground = True
    
    For t = 0 To 23
        B4XComboHours.cmbBox.Add(NumberFormat(t,2,0))
    Next

    For t = 0 To 55 Step 5
        B4XComboMins.cmbBox.Add(NumberFormat(t,2,0))
    Next

    B4XComboHours.cmbBox.SelectedIndex = Default / 60
    B4XComboMins.cmbBox.SelectedIndex = (Default Mod 60) / 5
    
    Dim rs As ResumableSub = Dialog.ShowCustom(p, "OK", "", "Cancel")
    
    Wait For (rs) Complete(Result As Int)
    
    If Result = xui.DialogResponse_Positive Then
        
        Default = (B4XComboHours.cmbBox.SelectedItem * 60) + B4XComboMins.cmbBox.SelectedItem
        
    End If
    
    Return Default '???????????
    
End Sub
 

DonManfred

Expert
Licensed User
Longtime User
 
Upvote 1

Mahares

Expert
Licensed User
Longtime User
I wish to send a value to a B4X Custom Dialogue as a default value, display the dialogue and allow the user to modify it, then perform a calculation with the resul
If you continue to have problems with CustomDialog even after Manfred redirected you, I think B4XPreferenceDialog might be the way to go for your situation.
 
Upvote 1

RichardN

Well-Known Member
Licensed User
Longtime User
If you continue to have problems with CustomDialog

Actually I did find some problems but probably due to my copy of the XUI Views.b4xlib being out of date.

As one of a number of .B4Xlib libraries residing in C:\Program Files (x86)\Anywhere Software\Basic4android\Libraries..... I thought this would have been one of the 'Core' libraries that gets updated with every new version of B4X ? Or am I mistaken?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
XUI Views is an internal library. Make sure to copy it to the internal libraries folder (C:\Program Files (x86)\Anywhere Software\<tool>\libraries).
 
Upvote 0

RichardN

Well-Known Member
Licensed User
Longtime User
@DonManfred...... Thank you for you BOLD statement. As I said, that is exactly where I found the (out of date) library in question.

The point I was making was that as an internal library I expected to find an up to date version included with the very recent B4A install (v11.0)

That did not appear to be the case..... hence my question.
 
Upvote 0
Top