Android Question customlistview loads max items and loads more when scroll tot bottom

m643

Member
Licensed User
Longtime User
Hi all,

I see in more and more apps that having a listview that loads for example 20 items and when you scroll down it loads another 20 items.
I am using now the customlistview class and that works great but I like the solutions that loads a max of items. I searched the forum but the only thing I found is the pull tot refresh class that is what I think simulair to this function. Unfortunately, I am not able tot modified this class so I'm looking for something like this.

Is there anybody who can help me?
 

DonManfred

Expert
Licensed User
Longtime User
If the Pulltorefresh has an Event which is called then you can load 20 more items in that event and add them at the end (or top; like you prefer)
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
Add this sub to CustomListView:
B4X:
Private Sub sv_ScrollChanged(Position As Int)
   If Position + sv.Height >= sv.Panel.Height Then
     If DateTime.Now > lastAddItemsTime + 200 Then
       lastAddItemsTime = DateTime.Now
       CallSub(CallBack, EventName & "_AddItems")
     End If
   End If
End Sub
Add this line to Class_Globals:
B4X:
Private lastAddItemsTime As Long

Now in your code you can handle the AddItems event and add items to the list:
B4X:
Sub CustomView1_AddItems
   Log("AddItems")
   For i = 1 To 20
     CustomView1.AddTextItem(i, i)
   Next
End Sub
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Excellent update, thanks Erel, will look more closely at this as I need to update an App I've got to work like this :)
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
Add this sub to CustomListView:
B4X:
Private Sub sv_ScrollChanged(Position As Int)
   If Position + sv.Height >= sv.Panel.Height Then
     If DateTime.Now > lastAddItemsTime + 200 Then
       lastAddItemsTime = DateTime.Now
       CallSub(CallBack, EventName & "_AddItems")
     End If
   End If
End Sub
Add this line to Class_Globals:
B4X:
Private lastAddItemsTime As Long

Now in your code you can handle the AddItems event and add items to the list:
B4X:
Sub CustomView1_AddItems
   Log("AddItems")
   For i = 1 To 20
     CustomView1.AddTextItem(i, i)
   Next
End Sub
this loop fills the same values 20 times each time , if i want to fill new values from a map containing 100 items , what it should be ?
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
Have you added 20 items from the map and now you want to add items 21 - 40 ?
Yes plz and if i want to add number of items only shown with the scrollview height and if there was a number of items wish is smaller than the scrollview height tnx
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
It is actually better to add a few more items than the visible items.

This code will add the next 20 items
B4X:
Sub CustomView1_AddItems
   Log("AddItems")
   Dim currentNumberOfItems = clv.GetSize
   For i = currentNumberOfItems   To Min(currentNumberOfItems + 20, Map.Size)
     CustomView1.AddTextItem(Map.GetValueAt(i), Map.GetValueAt(i))
   Next
End Sub
 
Upvote 0

Mrjoey

Active Member
Licensed User
Longtime User
It is actually better to add a few more items than the visible items.

This code will add the next 20 items
B4X:
Sub CustomView1_AddItems
   Log("AddItems")
   Dim currentNumberOfItems = clv.GetSize
   For i = currentNumberOfItems   To Min(currentNumberOfItems + 20, Map.Size)
     CustomView1.AddTextItem(Map.GetValueAt(i), Map.GetValueAt(i))
   Next
End Sub
clv.getsize is the number of items in the list? im sorry cz im using ClsChecklist class
 
Upvote 0

eps

Expert
Licensed User
Longtime User
Bump scrolling...

Initially you should get pages 1 and 2, displaying page 1, with page 2 off the page..

As soon as a User scrolls to page 2, you get page 3, etc...

If your User can go backwards and forwards you should keep 3 pages in memory. So you display the 'middle' page - unless you're at one of the ends...

They used to use it a lot in the Client Server stuff to keep network traffic down and server load etc..

HTH
 
Upvote 0

Douglas Farias

Expert
Licensed User
Longtime User
@Erel i m using your sample for the bottom, but dont understand how make this to TOP (up)
how to make this same for the TOP?

i have try to make the same like

B4X:
Private Sub sv_ScrollChanged(Position As Int)
   If Position + sv.Height >= sv.Panel.Height Then
 
     If DateTime.Now > lastAddItemsTime + 200 Then
       lastAddItemsTime = DateTime.Now
       CallSub(CallBack, EventName & "_AddItems")
     End If


   Else IF Position - sv.Height <= sv.Panel.Height Then

        If DateTime.Now > lastAddItemsTime + 200 Then
       lastAddItemsTime = DateTime.Now
       CallSub(CallBack, EventName & "_AddItems2")
     End If
  
   End If
End Sub

but dont work, when i slide to botton call _AddItems2 and not when i slide to up

i have try with postion = 0 but dont know if this is the best solution
B4X:
Private Sub sv_ScrollChanged(Position As Int)

   If Position + sv.Height >= sv.Panel.Height Then
   
         If DateTime.Now > lastAddItemsTime + 200 Then
           lastAddItemsTime = DateTime.Now
           CallSub(CallBack, EventName & "_AddItems")
         End If

  
   Else IF Position = 0 Then
  
            If DateTime.Now > lastAddItemsTime + 200 Then
           lastAddItemsTime = DateTime.Now
           CallSub(CallBack, EventName & "_AddItems2")
        End If
    
   End If
End Sub
 
Last edited:
Upvote 0

Alberto Michelis

Well-Known Member
Licensed User
Longtime User
Bump scrolling...

Initially you should get pages 1 and 2, displaying page 1, with page 2 off the page..

As soon as a User scrolls to page 2, you get page 3, etc...

If your User can go backwards and forwards you should keep 3 pages in memory. So you display the 'middle' page - unless you're at one of the ends...

They used to use it a lot in the Client Server stuff to keep network traffic down and server load etc..

HTH

Hi, any example of how to do this with CustomListView?
Thanks
 
Upvote 0

Kwame Twum

Active Member
Licensed User
Longtime User
Assuming cv is a CustomListView,
How can you control cv's .Add(panel,height,value) method to automatically push up the present items to display the incoming item?
I tried running
B4X:
cv.JumpToItem(cv.GetSize)
but the result is poor, as it adds the item below the screen's display, then pushes it up.
that looks very awkward.

Anyway to get this as smooth as possible?
Thank you.
 
Upvote 0
Top