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

Discussion in 'Android Questions' started by m643, Dec 16, 2013.

  1. m643

    m643 Member Licensed 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?
     
  2. DonManfred

    DonManfred Expert Licensed 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)
     
    Rusty likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    Add this sub to CustomListView:
    Code:
    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:
    Code:
    Private lastAddItemsTime As Long
    Now in your code you can handle the AddItems event and add items to the list:
    Code:
    Sub CustomView1_AddItems
       
    Log("AddItems")
       
    For i = 1 To 20
         CustomView1.AddTextItem(i, i)
       
    Next
    End Sub
     
    jmbm, peacemaker, fredo and 10 others like this.
  4. eps

    eps Well-Known Member Licensed 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 :)
     
  5. m643

    m643 Member Licensed User

    Thank erel I will try your solution
     
  6. Mrjoey

    Mrjoey Active Member Licensed User

    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 ?
     
  7. Erel

    Erel Administrator Staff Member Licensed User

    Have you added 20 items from the map and now you want to add items 21 - 40 ?
     
  8. Mrjoey

    Mrjoey Active Member Licensed User

    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
     
  9. Erel

    Erel Administrator Staff Member Licensed User

    It is actually better to add a few more items than the visible items.

    This code will add the next 20 items
    Code:
    Sub CustomView1_AddItems
       
    Log("AddItems")
       
    Dim currentNumberOfItems = clv.GetSize
       
    For i = currentNumberOfItems   To Min(currentNumberOfItems + 20Map.Size)
         CustomView1.AddTextItem(
    Map.GetValueAt(i), Map.GetValueAt(i))
       
    Next
    End Sub
     
    eps and lte5000 like this.
  10. Mrjoey

    Mrjoey Active Member Licensed User

    clv.getsize is the number of items in the list? im sorry cz im using ClsChecklist class
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    This thread is about CustomListView. You should start a new thread for your question.
     
  12. Mrjoey

    Mrjoey Active Member Licensed User

    no prob tnx for ur help :)
     
  13. eps

    eps Well-Known Member Licensed 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
     
  14. Douglas Farias

    Douglas Farias Expert Licensed 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

    Code:
    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
    Code:
    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: Jul 10, 2015
  15. Alberto Michelis

    Alberto Michelis Active Member Licensed User

    Hi, any example of how to do this with CustomListView?
    Thanks
     
  16. Kwame Twum

    Kwame Twum Active Member Licensed 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
    Code:
    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.
     
  17. DonManfred

    DonManfred Expert Licensed User

    You shopuld start a new thread for your question.
     
    Rusty and Kwame Twum like this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice