Android Question How to avoid Shifting in CustomListView?

FrankBerra

Active Member
Licensed User
Longtime User
Hi all

I am trying to modify the CustomListView class for letting me add items to bottom or to the top automatically when i scroll the list.
I get inspiration on Pull-to-refresh (https://www.b4x.com/android/forum/t...mlistview-with-pull-to-refresh-feature.27810/)
and these are my changes:
Code: Copy
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 & "_AddItemsBottom")
     End If
   End If
   
   If Position = 0 Then
     If DateTime.Now > lastAddItemsTime + 200 Then
       lastAddItemsTime = DateTime.Now
       CallSub(CallBack, EventName & "_AddItemsTop")
     End If
   End If
End Sub

But if i add items on top (index n. 0) all the following elements shift down.
I tryed to add the following codes to Sub InsertAtImpl

Code: Copy
Dim Position As Int = sv.ScrollPosition + dividerHeight + ItemHeight
'
'
' Original subroutine code here
'
'
sv.ScrollToNow(Position)

The code is not working as expected and the ListView is not scrolling to the original position

Any suggestions for fixing this behaviour?

Thanks in advance
 
Yes that's ok...but probably i didn't explained correctly

When try the example application it fills the scrollview with Item #1, Item #2, ecc
If i try to "pull" the scrollview it automatically adds a new item (TopPanel) at position 0 WITHOUT shifting down the other items...they don't move down in the screen but just adds a new item at position 0 that i can't see it utill i scroll down the scrollview completly.
But If i add a new item with CLV.InsertAt(0, ...) by pressing the button "Add item on top" (see attached example) it adds a new item at position 0 and alle the other items move down.

My question is: how can i add infinite elements in position 0 without scrolling down the others (like adding infinite top panels)? My goal is to create a infinite-scrolling effect like in chat applications

Thank you for your support
 

Attachments

Last edited:
Upvote 0
Exactly, as i said in the first post i modified the Sub InsertAtImpl with this codes:

Code: Copy
Dim Position As Int = sv.ScrollPosition + dividerHeight + ItemHeight'
'
' Original subroutine code here
'
sv.ScrollToNow(Position)

If i add one item everything works perfectly. But if i add, for example, 20 items at time (like adding for example 20 items of a chat conversation) it doesn't scroll correctly.
Take a look to the attached example an try to press on "Add 20 items" button

Any suggestion for fixing this problem?


I also tried to add DoEvents like this:
Code: Copy
Dim Position As Int = sv.ScrollPosition + dividerHeight + ItemHeight'
'
' Original subroutine code here
'
DoEvents
sv.ScrollToNow(Position)
DoEvents
...but in this case everything is so slow and you can notice a "bouncing" effect.
 

Attachments

Upvote 0
Back
Top