Android Question Split list into chunks

apty

Active Member
Licensed User
Longtime User
I have a list with 50 items. How can i split the list into 10 items each and load the first 10 in panel 1, the next 10 in panel 2 etc upto 5 panels?. The panels are from sliding panels tutorial.

I want each panel to hold 10 items (10 buttons to be specific).
 

Peter Simpson

Expert
Licensed User
Longtime User
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
I want each panel to hold 10 items (10 buttons to be specific).
Where is the problem? Iterate through the list and create a new panel on ever 10th item....
What have you tried so far? <- Do not expect us to write the code for you!
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
I tried the below code but it loads everything in first panel

B4X:
Dim panels(4) As Panel
    Dim lt As Int=0
    Dim tp As Int=0
    For i = 0 To panels.Length - 1
        panels(i).Initialize("panels")
        panels(i).Color = Colors.RGB(Rnd(0, 255), Rnd(0, 255), Rnd(0, 255))
        For j=0 To 50
            Dim btn As Button
            btn.Initialize("")
            btn.Text="Hi"
            panels(i).AddView(btn,Activity.Width/5*lt,Activity.Width/5*tp,100dip,100dip)
            lt=lt+1
            If lt=5 Then
                tp=tp+1
                lt=0
            End If
            If j=10 Then
               
                Activity.AddView(panels(i), 100%x, 0, 100%x, 100%y - 80dip)
                Activity.AddMenuItem("Panel #" & i, "Menu")
            End If
        Next
        
        

        
    Next
 
Upvote 0

apty

Active Member
Licensed User
Longtime User
The panels are added but all 50 buttons are on first panel. The rest 4 panels are empty with no buttons
 
Upvote 0

udg

Expert
Licensed User
Longtime User
I have a list with 50 items
Iterating from 0 to 50 gives you 51 items..
And
Dim panels(4)
gives you 4 panels (0 to three)..

j div 10 will give you 0 for first block (0..9), 1 for second block (10..19) and so on. So the integer part of the divison is what you need to identify the right panel.
j mod 10 will give you the "order position" of an item on its panel (returns 0..9)
 
Last edited:
Upvote 0

Star-Dust

Expert
Licensed User
Longtime User
Upvote 0
Top