Android Question CustomListView - "Object should first be initialized (B4XView)"

Rafael Grossi

Member
Licensed User
Hi guys,

I have a B4XPage with a CustomListView working well. In designer script page from CLV items, I added:
B4X:
DDD.CollectViewsData
and in the main code, it contains:

B4X:
    Sub Class_Globals
        Private LV1 As CustomListView
        Private dd As DDD
    End Sub
    
    Private Sub B4XPage_Created (Root1 As B4XView)
    '...'
    dd.Initialize
    xui.RegisterDesignerClass(dd)
End Sub

So I started a new B4XPage, with a new CustomListView (LV2). I also added in the designer script page of the new CLV items (different from the first one):
B4X:
DDD.CollectViewsData
and in main code of the new B4XPage:
B4X:
    Sub Class_Globals
        Private LV2 As CustomListView
        Private dd As DDD
    End Sub
    
    Private Sub B4XPage_Created (Root1 As B4XView)
    '...'
    dd.Initialize
    xui.RegisterDesignerClass(dd)
End Sub
But at this line:
B4X:
    xui.RegisterDesignerClass(dd)
it returns the error:
B4X:
Error occurred on line: 256 (DDD)
java.lang.RuntimeException: Object should first be initialized (B4XView).

I have tried to replace dd by dd2, without success.

How can I deal with it?
 

Rafael Grossi

Member
Licensed User
Thanks Erel, it worked! But...

I have supressed the Private dd As DDD and dd.Initialize.
I have replaced some items as you said, becoming: B4XPages.MainPage.dd.(......)
And kept the DDD.CollectViewsData in the second layout designer's script.
I'm not sure if I have to leave the xui.RegisterDesignerClass(B4XPages.MainPage.dd) but with or without it, the result seems to be the same.

Now the items are being added to CLV.

When a new item is added, i am having difficult to control its width:
- the green panel is the parent of the CLV (named LV2, magenta)
- orange is the panel from layout I used when adding an item

1747332211247.png


Each added item is created with small width. Some code I used:

B4X:
' My CLV (LVapa) proprieties:'
    LVapa.AsView.Width = 100%x - 40dip
    LVapa.sv.Width = LVapa.AsView.Width
   
'Adding new item:'
    LVapa.Add(CreateListItem("ABC", LVapa.AsView.Width, 100dip), "DEF")
    'If I replace LVapa.AsView.Width by 20dip or 500dip, the result is the same '
   
'At Private Sub CreateListItem I tried to add some code about the layout panel (PanelAPAs), with no effect:'
    B4XPages.MainPage.dd.GetViewByName(p, "PanelAPAs").Width = 100%x
   
'At item layout designer's script:'
    AutoScaleAll
    DDD.CollectViewsData
    PanelAPAs.Width = 100%x
    'No effect changing this value'

When I have many items and touch the magenta area, I can swipe de inside scrollview from CLV without problem.
The item click sub returns when I click just in the orange area.
And as I told in the first post, I have another CLV, with basically the same code, working well.
The small part we can see, with a house icon, show us the layout of the second CLV is right (because it's differente from the first CLV).

What am I doing wrong?
 
Upvote 0

Rafael Grossi

Member
Licensed User
Solved here using:
B4X:
LVapa.Base_Resize(LVapa.AsView.Width, LVapa.AsView.Height)
I don't know why the first CLV doesn't required this line and is working fine.
Thanks anyway!
 
Upvote 0
Top