Android Question How to set Top of XUI Views Dialog

AHilberink

Active Member
Licensed User
Longtime User
Hi,

How can I define Top or center a XUI View Dialog?

Looking at the XUI Views Example the following dialog is at top of the screen:
B4X:
Sub btnSearch_Click
    Wait For (Dialog.ShowTemplate(SearchTemplate, "", "", "CANCEL")) Complete (Result As Int)
    If Result = xui.DialogResponse_Positive Then
        btnSearch.xLBL.Text = SearchTemplate.SelectedItem
    End If
End Sub

Horizental is centered, but always on Top.
Is there a way to have it centered horizentally and vertically based on the format?

Kind regards,
André
 

coldtech

Member
Licensed User
Longtime User
I think you need to use a panel.

Look at this example:

This change seemed to work.
Sub btnCustom_Click
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 40%y, 300dip, 150dip)
p.LoadLayout("CustomDialog")

'dialog.PutAtTop = True 'put the dialog at the top of the screen
Wait For (dialog.ShowCustom(p, "OK", "", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
dialog.Show(fieldFirstName.Text & " " & fieldLastName.Text, "OK", "", "")
End If
End Sub

Not sure if there is another/better way.
 
Upvote 0

AHilberink

Active Member
Licensed User
Longtime User
I think you need to use a panel.

Look at this example:

This change seemed to work.
Sub btnCustom_Click
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0, 0, 40%y, 300dip, 150dip)
p.LoadLayout("CustomDialog")

'dialog.PutAtTop = True 'put the dialog at the top of the screen
Wait For (dialog.ShowCustom(p, "OK", "", "CANCEL")) Complete (Result As Int)
If Result = xui.DialogResponse_Positive Then
dialog.Show(fieldFirstName.Text & " " & fieldLastName.Text, "OK", "", "")
End If
End Sub

Not sure if there is another/better way.

Hi Coldtech,

Thank you for your reply. Sorry for my late response. I just had time to check your solution.

It seems not to work with a SearchTemplate, only with EditText. It also works only with BX4Pages.lib and not XUI Views.lib only. My project is not already a BX4Pages project.

If there is another solution, please let me know.

Kind regards,
André
 
Upvote 0

zed

Well-Known Member
Licensed User
This code positions Dialog in the center of the screen.

B4A:
Sub btnShow_Click
    Dialog.PutAtTop = False

    ' Shows dialog
    Dim sf As Object = Dialog.ShowTemplate(SearchTemplate, "OK", "", "CANCEL")

    ' Allow time for the layout to be created
    Sleep(0)

    ' Now Dialog.Base exists and is the correct size
    Dim b As B4XView = Dialog.Base
    b.Top = (Activity.Height - b.Height) / 2

  
    Wait For (sf) Complete (Result As Int)

    If Result = xui.DialogResponse_Positive Then
        ToastMessageShow("You wrote: " & SearchTemplate.Text, False)
    Else
        ToastMessageShow("Canceled", False)
    End If
End Sub
 
Upvote 0
Top