Android Question loading layout inside scrollview

apty

Active Member
Licensed User
Longtime User
I want to load a layout several times in a scrollview. I have tried the below code but the layout is not showing. Kindly assist
B4X:
Dim btn As Int=0
For i = 0 To 9
        Dim panelx As Panel

        panelx.Initialize("")
        panelx.LoadLayout("pnltest")
       
        ScrollView1.Panel.AddView(panelx, 0, btn,400dip,400dip)
btn=btn+410dip
    Next
   
    ScrollView1.Color=Colors.Green
   
    ScrollView1.Panel.Height = 1000dip
 
Last edited:

DonManfred

Expert
Licensed User
Longtime User
Use xcustomlistview. It´s easier and more powerful.
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
please can you help with an example of how to load layouts several times using xcustomlistview.?
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
https://www.b4x.com/android/forum/t...listview-cross-platform-customlistview.84501/

B4X:
Sub Activity_Create(FirstTime As Boolean)
    Activity.LoadLayout("1")
    clv1.AddTextItem("1Aaaa" & CRLF & "Bbbb", "b")
    clv1.AddTextItem("2Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc", "c")
    clv1.AddTextItem("3Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" , "d")
    clv1.AddTextItem("4Aaaa" & CRLF & "Bbbb" & CRLF & "Cccc" & CRLF & "Dddd" & CRLF & "Eeee", "e")
    For i = 1 To 20
        clv2.Add(CreateListItem($"Item #${i}"$, clv2.AsView.Width, 60dip), $"Item #${i}"$)
    Next
End Sub
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As Panel
    p.Initialize("")
    p.SetLayout(0, 0, Width, Height)
    p.LoadLayout("CellItem")
    Label1.Text = Text
    Return p
End Sub
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
when i try the above i get an error
java.lang.NullPointerException: Attempt to write to field 'int anywheresoftware.b4a.BALayout$LayoutParams.left' on a null object reference

Also the customlistview gives an error on the line below:
lbl.SingleLine = False
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
i have watched the video and added the view as required but i still get the same error.
Even the attached example on the xcustomlistview gives an error on the below line:
lbl.SingleLine = False

"unknown member:singeline
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
I have downloaded and tried but it doesn't work on my end. After commenting out lbl.SingleLine = False it compiles fine but force closes on the device
 
Upvote 0
Top