B4J Question [SOLVED]B4XPages / Try to understand xCustomListView

christianjeannot

Member
Licensed User
Hello Community,

I try to understand the handling of xCustomView for my project and checked some threads like this one.

I use the following code to see how it works.

B4X:
#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region

'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip

Sub Class_Globals
    Private Root As B4XView
    Private xui As XUI
    Private Label1 As B4XView
    Public CLV As CustomListView
    Private Button1 As B4XView
End Sub

Public Sub Initialize
        
End Sub

Sub AppStart
    For i = 1 To 10
        Dim pnl As B4XView = CreateItem("Zeile" & i)
        CLV.Add(pnl,i)
    Next
End Sub

'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    Root.LoadLayout("MainPage")
    
End Sub

'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.

Sub CreateItem(Title As String) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.LoadLayout("ItemsLayout")
    p.SetLayoutAnimated(0, 0, 0, p.Width, p.Height)
    Label1.Text = Title
    Return p
End Sub

Private Sub Button1_Click
    AppStart
End Sub

I got a strange result (Screenshot attached).

I expected to have 10 lines with a text in each line.

Someone please has an information what I missed?

Best regards

--Christian
 

Attachments

  • B4X_Result_CustomView.PNG
    B4X_Result_CustomView.PNG
    17.3 KB · Views: 230

stevel05

Expert
Licensed User
Longtime User
p.width and p.height will both have a value of 0 in p.SetLayoutAnimated called in the CreateItem sub, try changing them to something more appropriate like CLV.AsView.Width and 30 maybe
 
Last edited:
Upvote 0

christianjeannot

Member
Licensed User
@stevel05
Thank you for your information. I tested several values for p.width and p.height. With 180 and 30 I was able to see the correct result. I will test with some values to see what makes sense to use.
 
Upvote 0

Andrew (Digitwell)

Well-Known Member
Licensed User
Longtime User
I would recommend using a background panel on the layout "itemslayout" to get the size.

then you can use this panel to size the clvitem. The background panel should not use layout constraints.

B4X:
Sub CreateItem(Title As String) As B4XView
    Dim p As B4XView = xui.CreatePanel("")
    p.LoadLayout("ItemsLayout")
    p.SetLayoutAnimated(0, 0, 0, pnlBack.Width, pnlBack.Height)
    Label1.Text = Title
    Return p
End Sub
 
Upvote 0
Top