You really should learn how to use parameterized queries.
The problem is here.
Read this:
https://www.b4x.com/android/forum/t...om-clv-or-any-other-container.117992/#content
Hello
@Erel ,
as always, you inspired me
The problem:
- I have two CLV, let's say: CLV1 and CLV 2
- I tried to load the layout containing CLV2 in a panel in CLV1 and, IN createPanel routine of CLV1, call createPanel in CLV2 also. This is the problem: the panel in CLV1 containing CLV2 isn't created yet before "return p"... As CLV is a CLASS, CLV2 isn't instatiated yet and cannot run the method add. Then, trying to add panels in CLV2 inside the routine that loads itself in CLV1 is an error.
What did I do:
- Defined CLV2 also as a class Global customview with an unique name (then I don't need to worry about referencing later with a tag, getview... as described
here )
- Loaded the design containing CLV2 with a createpanel routine in CLV1... in this routine I don't try to create the panels in CLV2
- AFTER CreatePanel in CLV1 finishes, then add panels in CLV2 (outisde this routine)
The code is something like Ths:
Sub Class_Globals
Private CLV1 As CustomListView
Private CLV2 As CustomListView <--- This CLV will be in an item in CLV1
End Sub
...
Public Sub createPage(idRestCreate As Long)
...
CLV1.Add(createOfertas,"ofertas")
'### Here the Class CLV2 is instantiated and ready to receive items
query = "select * from sample"
cursor2 = B4XPages.MainPage.sql1.ExecQuery(query)
Do While cursor2.NextRow
CLVOfertas.Add(createOfertasItens,"ofertas")
Loop
cursor2.Close
End Sub
Private Sub createOfertas As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0,0,0,100%x,200dip)
p.LoadLayout("restaurantMenuOfertas") <--- This design contains CLV2
Return p
End Sub
Private Sub createOfertasItens As B4XView
Dim p As B4XView = xui.CreatePanel("")
p.SetLayoutAnimated(0,0,0,100%x,200dip)
p.LoadLayout("restaurantMenuOfertaItem") <--- This design contains each item in CLV2
p.Width = 80dip
p.Height = 200dip
Return p
End Sub
That's it! I think that using the method described by
@Erel in the thread that he referenced you can avoid the need for registering CLV2 as a global class object and opens the possibility to dynamically create many copies in many items inside a "parent" clv1, referencing those later with getview using tags, but I didn't tested this.
I hope that this thread could be useful to community.
Thanks
@Erel !!!