Android Question LoadLayout and CustomListView

Haris Hafeez

Active Member
Licensed User
Longtime User
Hello All,

I am aware that there is a similar thread here but the discussion there has not quite helped me.

Previously in B4A, I used to have create a CLV object, add it to the activity(100%x,100%y) and then iterate over a collection and add items to the CLV by creating a panel and loading that panel's layout from a layout file.

This approach no longer works correctly. Now I get the warning message:

'Panel size is unknown. Layout may not be loaded correctly.'

I have tried the workaround suggested on the above referenced thread but that doesn't help me. Even if that works, I want to know if this is an Android 5.x change that has caused this or is it specific to B4A?

Here is the code where I'm trying to load the CLV layout.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    Dim dummyPanel As Panel
    dummyPanel.Initialize("")
    Activity.AddView(dummyPanel,0,0,100%x,100%y)
    dummyPanel.Width = 100%x 'removing or leaving these two lines also don't make any difference
    dummyPanel.Height = 100%y 'as above
    dummyPanel.LoadLayout("MyCLVLayout")
'    dummyPanel.RemoveView 'removing or leaving this doesn't make any difference
End Sub

Then in Resume:
B4X:
    Dim l As List = GetAllObjectKeys
    For Each key As String In l
        Dim p As Panel = CreateItemPanel(key) 'this method loads the item layout
        myCLV.Add(p, 124dip, key) 'myCLV was defined by right clicking in the designer
        p.Height = 120dip
    Next
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Have you seen the updated example of CustomListView: https://www.b4x.com/android/forum/t...ew-a-flexible-list-based-on-scrollview.19567/ ?
It uses LoadLayout to create the items.

With the new version of CustomListView it is simpler to add the list with the visual designer. You don't need to do anything special for it to be loaded correctly.

When you load the items themselves you do need to create a "dummy" panel so the size will be known.
 
Upvote 0

Haris Hafeez

Active Member
Licensed User
Longtime User
Thanks. Yes I was loading CLV from the layout. However, I discovered a slightly different way to load the item layout.
B4X:
    Dim p As Panel
    p.Initialize("")
    myCLV.Add(p, 130dip, key)
    p.Height = 124dip
    p.LoadLayout("ItemLayout")

In this code I don;t need to add a panel to the activity and then remove it but I'm wondering if this can cause issues? For now the item layout seems fine.
 
Upvote 0
Top