Android Question How do I load multiple customlistviews on to may main activity?

MrKim

Well-Known Member
Licensed User
Longtime User
HERE: https://www.b4x.com/android/forum/t...ew-cross-platform-customlistview.84501/page-2

Erel says
xCustomListView as well as the latest versions of CLV must be added with the designer. You can create a layout file with only a CLV and load it whenever you want to create one.

Forgive me for being dense but how do you do that? I need to load multiple xcustomlistviews at run time in to Layout "MAIN". The number needed is unknown and I simply want to add them as needed. I have been using the customlistview class and could add them at will.

I created a separate layout with only a CLV, But how do I load it on to MAIN and reference it? I can't get it as a view because it is a B4X view. I am lost.
 

udg

Expert
Licensed User
Longtime User
One way could be to add panels to Main when needed. For each panel you add, use LoadLayout where the layout is the one with the xCLV you prepared as a general model.
Depending on how the layout is designed, you may reach the xCLV with panel.getview(x)
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
One way could be to add panels to Main when needed. For each panel you add, use LoadLayout where the layout is the one with the xCLV you prepared as a general model.
Depending on how the layout is designed, you may reach the xCLV with panel.getview(x)
I need a specific example.
in the code below
B4X:
  Dim SWL As CustomListView = P.GetView(0)
gives the warning
Types Do not match
And a later attempt to reference the .AsView Property results in
B4X:
java.lang.RuntimeException: Method: _asview not found in: anywheresoftware.b4a.BALayout

B4X:
    Dim P As Panel
    P.Initialize("")
    P.LoadLayout("SWL")
    'Activity.LoadLayout("SWL")
    Log(P.NumberOfViews)
    Dim SWL As CustomListView = P.GetView(0)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Dim P As Panel
P.Initialize("")
P.LoadLayout(
"SWL")
Bug: never load a layout before you set the panel size.

B4X:
Dim p As B4XView = XUI.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, ...)
p.LoadLayout("SWL")
p.Tag = CustomListView1 'name from layout file
'... later:
Dim clv As CustomListView = p.Tag
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
Bug: never load a layout before you set the panel size.

B4X:
Dim p As B4XView = XUI.CreatePanel("")
p.SetLayoutAnimated(0, 0, 0, ...)
p.LoadLayout("SWL")
p.Tag = CustomListView1 'name from layout file
'... later:
Dim clv As CustomListView = p.Tag
Sigh, Still don't get it. Cannot get it to display. Where do I declare CustomListView1 (in my case SWLCLV)
I have stripped it down to this.
B4X:
Sub Process_Globals
    Private xui As XUI
    
End Sub

Sub Globals
    Private SWLCLV As CustomListView




End Sub

Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("main")
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, 100%x,  100%y)
    p.LoadLayout("SWL")
    p.Tag = SWLCLV 'name from layout file
    '... later:
    Dim SWL As CustomListView = p.Tag
    
    SWL.DefaultTextColor = xui.Color_White
    SWL.DefaultTextBackgroundColor = xui.Color_Blue
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")
    SWL.AddTextItem("srlih sfliuh wriuh wreiuhw rgivuh wugih iwuhreg iuh iuh tregvwiuh ", "SDFG")

End Sub   'Activity_Create


Sub SWLCLV_ItemClick (Index As Int, Value As Object)
    Log(Index)
End Sub
What am I missing?
Is there some tutorial I should read to understand this?
 
Upvote 0

MrKim

Well-Known Member
Licensed User
Longtime User
You haven't added P to the activity.

Change your code to:
B4X:
Dim p As B4XView = xui.CreatePanel("")
Activity.AddView(p, 0, 0, 100%x, 100%y)
p.LoadLayout(...)
ME slapping my forehead:p:eek::rolleyes:DOH!
 
Upvote 0
Top