Android Code Snippet [XCustomListView] Page Indicator

Hello everyone in the community, I was looking for a code that would help me indicate the pagination a CustomListView and know in which position the list was indicated.

I managed to create a simple code to be able to do it.

If you can improve it, please follow the thread of this post.



B4X:
Private Sub xCustomListView1_ScrollChanged (Offset As Int)

    Dim index As Double = Round((Offset / xCustomListView1.AsView.Width) + 1)
    xCustomListView1.JumpToItem(index-1)

End Sub

Private Sub xCustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)

    LabelIndicator.Text = $"${(LastIndex+1)}/${xCustomListView1.Size}"$

End Sub
 

Brian Michael

Member
Licensed User
EDIT:

I found an error when indicating the first and last index, so I solved it this way:


B4X:
Private Sub xCustomListView1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)   



If LastIndex = 0 Then

        LabelIndicator.Text = $"${1}/${xCustomListView1.Size}"$

    Else if LastIndex = Profile_infoList.Size Then

        LabelIndicator.Text = $"${xCustomListView1.Size}/${xCustomListView1.Size}"$

    Else

        LabelIndicator.Text = $"${(LastIndex+1)}/${xCustomListView1.Size}"$

    End If



End Sub
 
Top