Android Code Snippet CustomLayoutDialog with CustomListView

SS-2017-07-30_08.57.08.png


1. Create a layout file with a CustomListView. Make sure that the CLV is anchored to all sides:

SS-2017-07-30_08.57.39.png


2. Create the dialog:

B4X:
Sub Activity_Click
   Dim cd As CustomLayoutDialog
   cd.ShowAsync("Choose item", "", "", "", Null, False)
   cd.SetSize(100%x, 100%y) 'request maximum size
   Wait For Dialog_Ready (DialogPanel As Panel)
   DialogPanel.LoadLayout("CustomDialogLayout")
   For i = 1 To 20
     CLVDialog.AddTextItem("Item #" & i, i)
   Next
   Wait For CLVDialog_ItemClick (Index As Int, Value As Object)
   Log("Selected item: " & Value)
   cd.CloseDialog(DialogResponse.POSITIVE)
End Sub
 
Last edited:

fredo

Well-Known Member
Licensed User
Longtime User
The CustomLayoutDialog is really helpful since it is now really easy to create "fancy" dialogs via the Visual designer.

But how could we dismiss it if the user taps BACK?

B4X:
Sub Globals
    Dim cd As CustomLayoutDialog
        ...
end sub

Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
    Select KeyCode
        Case KeyCodes.KEYCODE_BACK
            cd.CloseDialog(DialogResponse.CANCEL)
            Return True
    End Select
End Sub
 

hibrid0

Active Member
Licensed User
Longtime User
I have an old app with xcustomview and not show items. Any update? If I add customelistview not show items, if I compile the sample work fine.
 

cxbs

Active Member
Licensed User
Longtime User
If the customlayoutdialog can customize the display position instead of the default center display, it will be more perfect!
 
Top