Android Question [Solved] [B4X] XUI Views assistance required: "Dialog.ShowCustom(..."


Well-Known Member
Licensed User
In a certain project, all "outdated" CustomLayoutDialogs are to be converted to "[B4X] XUI Views".

After looking at some examples the creation of a custom dialog is basically no problem.

Nevertheless, I still don't seem to do everything right, because the following display errors occur in the enclosed example project:

1.) At the first call of the dialog the "B4XFloatTextField" is not displayed, at the second call it is.

2.) The height of the "B4XFloatTextField" is not displayed as intended.​


#Region  Project Attributes
    #ApplicationLabel: B4A Example
    #VersionCode: 1
    'SupportedOrientations possible values: unspecified, landscape or portrait.
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes
    #FullScreen: true
    #IncludeTitle: false   
#End Region

Sub Process_Globals
End Sub

Sub Globals
    Private Base As B4XView
    Private xuiDialog As B4XDialog
    Private xuiDialogPanel2 As B4XView
    Private B4XFloatTextField1 As B4XFloatTextField
End Sub

Sub Activity_Create(FirstTime As Boolean)
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub

Sub XuiInits As ResumableSub
    ' [B4X] XUI Views - Cross platform views and dialogs
    '         Erel -->
    '         Erel -->
    Base = Activity

    xuiDialog.Initialize (Base)
    xuiDialog.BackgroundColor = Colors.White
    xuiDialog.BlurBackground = True
    xuiDialog.BorderColor = Colors.ARGB(11,11,11,11)
    xuiDialog.ButtonsColor = Colors.Transparent
    xuiDialog.TitleBarColor = Starter.intColorPrimaryLight
    xuiDialog.ButtonsTextColor = Starter.intColorAccent
    xuiDialog.ButtonsOrder = Array As Int(Starter.XUI.DialogResponse_Negative, Starter.XUI.DialogResponse_Cancel, Starter.XUI.DialogResponse_Positive)
    xuiDialogPanel2 = Starter.XUI.CreatePanel("")
    Return Null
End Sub

Sub Button1_Click As ResumableSub
    ' Custom dialog
    If Not(xuiDialog.IsInitialized) Then
        wait for(XuiInits) complete(x As Object)
    End If
    Dim InputFieldHeight As Int = 48dip *3
    xuiDialogPanel2.SetLayoutAnimated(0, 0, 0, 98%x, InputFieldHeight) 
    xuiDialog.Title = "yyy title"
    xuiDialog.PutAtTop = True
    Dim rs As ResumableSub = xuiDialog.ShowCustom(xuiDialogPanel2, "OK", "", "Cancel")
    Dim ok As B4XView = xuiDialog.GetButton(Starter.XUI.DialogResponse_Positive)
    Dim cancel As B4XView = xuiDialog.GetButton(Starter.XUI.DialogResponse_Cancel)
    ok.SetLayoutAnimated(0, ok.Parent.Width / 2 + 2dip, ok.Top, ok.Parent.Width / 2 - 4dip, ok.Height)
    cancel.SetLayoutAnimated(0, 2dip, cancel.Top, cancel.Parent.Width / 2 - 4dip, cancel.Height)

    B4XFloatTextField1.mBase.Height = InputFieldHeight

    B4XFloatTextField1.mBase.Color = Colors.DarkGray ' .White
    B4XFloatTextField1.HintColor = Colors.Yellow
    B4XFloatTextField1.Focused = True
    B4XFloatTextField1.HintText = "yyy hinttext"
    B4XFloatTextField1.Text = "This is a preset text"
    Wait For (rs) Complete (Result As Int)
    If Result = Starter.XUI.DialogResponse_Positive Then
        Log("#-  x2188,  B4XFloatTextField1.Text=" &  B4XFloatTextField1.Text)
    End If
    Return Null

End Sub

What am I doing wrong?


    11 KB · Views: 151


Well-Known Member
Licensed User
Why aren't you using B4XInputTemplate?
The layout used here should be as simple as possible for getting started with ShowCustom() before using more complex layouts.​

No reason for XuiInits to be a resumable sub.
This is a leftover from several awkward sleep() attempts.​

Don't ignore this very important warning:
Panel size is unknown. Layout may not be loaded correctly.
That's for sure. Age-related temporary technician arrogance to harmless looking hints often leads unnecessarily to time-consuming loss of productivity.​

Load the layout after you call xuiDialogPanel2.SetLayoutAnimated
That was it. Thank you.​
Upvote 0