B4A Library [B4X][XUI] CLVIndexScroller - xCustomListView fast scrolling index view

It's a class that adds a fast scrolling index view to xCustomListView. It has a dark and a light mode. You can show either alphabetic or numeric index and can change the index order.

ezgif.com-optimize2.gif
ezgif.com-crop.gif


Dependencies:
  1. xCustomListView
  2. XUI / jXUI
Note:
  1. CLV items must be in sorted order.
  2. CLV items should have a label.
  3. CLVIndexScroller will scroll CLV depending upon the first label view of the CLVItem.
  4. After adding/removing CLV items remember to call CLVIndexScroller Refresh function.
Usage:
B4X:
Dim clv As CustomListView
Dim clvIS As CLVIndexScroller

For i=0 To 25
    For j=0 To 7
        clv.AddTextItem(Chr(i+65) & "-Lorem Ipsum" ,"")
    Next
Next
''Initialize (clv As CustomListView, IndexTypeNumeric As Boolean, DarkTheme As Boolean, AscendingOrder As Boolean)
clvIS.Initialize(clv,False,True,True)

''Change active item color
clvIS.SetActiveColor(Colors.Green)

''Set active index theme
clvIS.SetActiveIndexTheme(clvIS.ACTIVE_INDEX_THEME_AUTOPOS)

''Call update to refresh the active index while manual scrolling
Sub clv_ScrollChanged (Offset As Int)
    clvIS.Update
End Sub

It's compatible with B4A, B4I and B4J.

Update 1.01:
Fixed crash issue when adding a panel instead of a text item.
Update 1.10: Added two active index theme fixed and auto position (check image).clvIS.SetActiveIndexTheme(clvIS.ACTIVE_INDEX_THEME_AUTOPOS)
 

Attachments

  • CLVIndexScroller.bas
    4.7 KB · Views: 415
Last edited:

Sergio Haurat

Active Member
Licensed User
Longtime User
Please update these lines to prevent the IDE from displaying a warning that the data type is object

Add .As (Int):
'Real lines: 132, 137 and 139
For i=0 To mCLV.Size-1
  For Each v As B4XView In mCLV.GetPanel(i).GetAllViewsRecursive
    If v Is Label Then
      If ((v.Text.ToUpperCase.CharAt(0)&"").GetBytes("ASCII")(0) >= fromChr And (v.Text.ToUpperCase.CharAt(0)&"").GetBytes("ASCII")(0) <= toChr) Then
        For Each la As B4XView In Base.GetAllViewsRecursive
          If la.Text.CharAt(0) = v.Text.ToUpperCase.CharAt(0) Then
            If la.Tag.As (Int) = -1 Then la.Tag = i
          End If
        Next
      Else
        If AscOrder Then
          If Base.GetView(Base.NumberOfViews-1).Tag.As (Int) = -1 Then Base.GetView(Base.NumberOfViews-1).Tag = i
        Else
          If Base.GetView(0).Tag.As (Int) = -1 Then Base.GetView(0).Tag = i
        End If
      End If
      Exit
    End If
  Next
Next
 

Sergio Haurat

Active Member
Licensed User
Longtime User
To make it compatible with B4i you need to change line 129 to:
B4X:
Dim b() As Byte = v.Text.ToUpperCase.CharAt(0).As(String).GetBytes("ASCII")
If (b(0) >= fromChr And b(0) <= toChr) Then
It worked perfectly

Thanks Erel!
 
Last edited:

Theera

Well-Known Member
Licensed User
Longtime User
Is there example for test?
 
Top