Android Question Customlistview Snap to Card


Active Member
Licensed User

I'm trying to modify the CustomListView.bas module as follows:

1. I want it to snap to each panel. Like the way it snaps when executing a Jump to Item.
2. I want it to only be activated when a user swipes.

The behaviour could basically be described as swiping between cards/panels. Swipe left for previous item, swipe right for next item.

I have taken a look at the module, but unfortunately am still a bit too new at B4x to fully understand the implementation.

Can you please provide some pointers as to how this could be accomplished and which methods would have to be modified?



Staff member
Licensed User
I'm trying to modify the CustomListView.bas module as follows:
This is a mistake. Use the library.

You can handle the ScrollChanged event to do what you need.

Sub CLV1_ScrollChanged (Offset As Int)
   ScrollIndex = ScrollIndex + 1
   Dim MyIndex As Int = ScrollIndex 'ScrollIndex as a global int variable
   If ScrollIndex <> MyIndex Then Return
   Dim VisibleIndex As Int = CLV1.FirstVisibleIndex
   Dim RawItem As CLVItem = CLV1.GetRawListItem(VisibleIndex)
   Dim CurrentOffset As Int =
   If CurrentOffset - RawItem.Offset > RawItem.Size / 2 Then
       CLV1.ScrollToItem(VisibleIndex + 1)
   End If
End Sub