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.
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
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
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
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
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
@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
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.