B4A Library [Lib] UltimateListView

I've been working on this project for a long time and I'm very proud to release the version 4 today.

The UltimateListView is, as its pompous name says, THE ListView.

  • It can handle very long lists. This is a screenshot of a list with 245813 items, all different:

    verylonglist.jpg


  • It can mix different layouts (and they can be changed dynamically). You can use it as an expandable ListView:

    layouts.jpg


  • It has a low memory footprint and is very fast (this report comes from the Performance demo where the list has to display 128901 distinct words read from a database and the used device is a Huawei Honor single core 1.4 Ghz):

    performance.png


  • It can scroll in both directions thanks to its swipe detector:

    tables.jpg


  • The swipe detector can also be used to implement a swipe-to-dismiss or a swipe-to-reveal:

    swipedetector.png
  • You can easily add editors to your table to change its content:

    celledit.jpg


  • You can animate the items when they are added, removed, replaced or when the list is scrolled (with your own custom animation):

    animationclap.png


  • It can stack items from the bottom:

    stackfrombottom.png


  • It supports drag & drop operations (internal & external):

    dragndrop.png


  • You can synchronize lists with different item heights:

    grid.jpg
The examples will show you how to implement a Pull-to-Refresh, create sticky headers or combine several lists to make a wheel. One of the examples is an improved version of my File Explorer class.

All texts and images can be loaded asynchronously (from Internet, from a database or from a local folder), so you can scroll even if the data are not fully loaded.

The list has its own state manager.

Since September 2018, ULV is available for free. You can still donate for it if you wish.
To send the money, just click on the Donate button below (the amount to enter is in euros):


Note that UltimateListView is not a wrapper around the work of someone else. It is 100% my own code and it is based upon the standard Java ListView of Android.

The UltimateListView does not work with Android versions < 2. It cannot work with B4J or B4i.

Current version: 4.50

DOWNLOAD HERE:
 
Last edited:

Raul Cavaca

Member
Licensed User
Longtime User
Hello,

I have a problem with my TreeList.

I have in Child_Layout with one checkbox and to click work fine (event checkedChange fire) , but the problem is when move the scroll of the list the event return fire and value checked is false.

Thanks
 

Raul Cavaca

Member
Licensed User
Longtime User
B4X:
Public Sub Initialize(Activ As Activity,Portrait As Boolean,Modulo As Object)

ULV.Initialize(0, 0, "", "ULV")
ULV.FastScroller(True)
ULV.SetPadding(2dip, 1dip, 2dip, 2dip)
ULV.SetStyle(ULV.STYLE_HOLO_LIGHT)
ULV.AddLayout("PARENT_NODE", "Parent_LayoutCreator", "Parent_ContentFiller", 50dip, True)
ULV.AddLayout("CHILD1_NODE", "Child1_LayoutCreator", "Child1_ContentFiller", 130dip, True)


Activ.AddView(ULV, 2dip, 55dip, 100%x - 2dip, 100%y - 60dip)

End Sub

Sub Parent_LayoutCreator(LayoutName As String, LayoutPanel As Panel)

Dim PanelTitle As Panel
PanelTitle.Initialize("")
Dim cd As ColorDrawable
cd.Initialize(Colors.RGB(235,235,235), 5dip)
PanelTitle.Background = cd
LayoutPanel.AddView(PanelTitle, 0dip, 0dip, LayoutPanel.Width-2dip, OriginalHeight - 2dip)

Dim lblRepositorio As Label
lblRepositorio.Initialize("")
lblRepositorio.color = Colors.Transparent
lblRepositorio.TextColor = Colors.RGB(31,0,209)
lblRepositorio.TextSize = 16
lblRepositorio.Typeface = Typeface.DEFAULT_BOLD
lblRepositorio.Gravity = Gravity.CENTER_VERTICAL
LayoutPanel.AddView(lblRepositorio, 10dip, 2dip, LayoutPanel.Width - 10dip,40dip)



End Sub

Sub Child1_LayoutCreator(LayoutName As String, LayoutPanel As Panel)


LayoutPanel.Color = Colors.White

'---------------------------Cabecalho----------------------------------------
Dim PanelTitle As Panel
PanelTitle.Initialize("VerDetalhe")
Dim cd As ColorDrawable
'cd.Initialize(Colors.RGB(245,245,245), 7dip)
cd.Initialize(Colors.RGB(245,245,245), 7dip)
PanelTitle.Background = cd
LayoutPanel.AddView(PanelTitle, 0dip, 0dip, LayoutPanel.Width-2dip, 35dip)

cvsDescricao.Initialize(PanelTitle)


Dim chkValidar As CheckBox
chkValidar.Initialize("chkValidar")
chkValidar.Gravity = Gravity.TOP
LayoutPanel.AddView(chkValidar, LayoutPanel.Width -40dip, 2dip, 60dip ,60dip)


'-----------------------------------------------------------------------------------'
End Sub

Sub Parent_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)

Dim Repositorio As String = SaveState.lstLogsCommits.Get(ItemID)
'
' '--------------------------------------------Cabecalho-----------------------------------------------

Dim Rep As Label = LayoutPanel.GetView(1)
Dim iv As ImageView = LayoutPanel.GetView(2)

Rep.Text = Repositorio


If ULV.IsExpanded(ItemID) Then
iv.Bitmap = LoadBitmap(File.DirAssets,"iconUp.png")
Else
iv.Bitmap = LoadBitmap(File.DirAssets,"iconDown.png")
End If

iv.Gravity = Gravity.FILL


'--------------------------------------------------------------------------------------------------------------



End Sub


Sub Child1_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)

Dim LogCommit As eLogCommit
LogCommit.Initialize

If ItemID Mod ChildrenMultiple <= SaveState.lstLogsCommitsDetalhe.Size Then
LogCommit = SaveState.lstLogsCommitsDetalhe.Get(ItemID Mod ChildrenMultiple)
End If

'--------------------------------------------Cabecalho-----------------------------------------------
Dim pnl As Panel = LayoutPanel.GetView(0)
Dim lblUtilizador As Label = LayoutPanel.GetView(1)
Dim lblDataHora As Label = LayoutPanel.GetView(2)
Dim chkValidar As CheckBox = LayoutPanel.GetView(3)
Dim lblDescricao As Label = LayoutPanel.GetView(4)
Dim lblInfoIncidente As ImageView = LayoutPanel.GetView(5)
Dim lblPasta As Label = LayoutPanel.GetView(7)

pnl.Tag = ItemID Mod ChildrenMultiple

If LogCommit.Validado Then
pnl.Background = cdValidado
Else
pnl.Background = cdNaoValidado
End If

lblUtilizador.Text = LogCommit.Utilizador
lblDataHora.Text = LogCommit.strDataHora


chkValidar.Checked = LogCommit.Validado

chkValidar.Tag = ItemID Mod ChildrenMultiple


'--------------------------------------------------------------------------------------------------------------


End Sub

Sub chkValidar_CheckedChange(Checked As Boolean)

Dim chk As CheckBox
chk = Sender


If chk.Tag <> Null AND IsNumber(chk.Tag) Then

Dim ValidarCommit As eLogCommit = SaveState.lstLogsCommitsDetalhe.Get(chk.Tag)

ValidarCommit.Validado = Checked

ULV.RefreshContent


End If

End Sub
 

Informatix

Expert
Licensed User
Longtime User
B4X:
Public Sub Initialize(Activ As Activity,Portrait As Boolean,Modulo As Object)

ULV.Initialize(0, 0, "", "ULV")
ULV.FastScroller(True)
ULV.SetPadding(2dip, 1dip, 2dip, 2dip)
ULV.SetStyle(ULV.STYLE_HOLO_LIGHT)
ULV.AddLayout("PARENT_NODE", "Parent_LayoutCreator", "Parent_ContentFiller", 50dip, True)
ULV.AddLayout("CHILD1_NODE", "Child1_LayoutCreator", "Child1_ContentFiller", 130dip, True)


Activ.AddView(ULV, 2dip, 55dip, 100%x - 2dip, 100%y - 60dip)

End Sub

Sub Parent_LayoutCreator(LayoutName As String, LayoutPanel As Panel)

Dim PanelTitle As Panel
PanelTitle.Initialize("")
Dim cd As ColorDrawable
cd.Initialize(Colors.RGB(235,235,235), 5dip)
PanelTitle.Background = cd
LayoutPanel.AddView(PanelTitle, 0dip, 0dip, LayoutPanel.Width-2dip, OriginalHeight - 2dip)

Dim lblRepositorio As Label
lblRepositorio.Initialize("")
lblRepositorio.color = Colors.Transparent
lblRepositorio.TextColor = Colors.RGB(31,0,209)
lblRepositorio.TextSize = 16
lblRepositorio.Typeface = Typeface.DEFAULT_BOLD
lblRepositorio.Gravity = Gravity.CENTER_VERTICAL
LayoutPanel.AddView(lblRepositorio, 10dip, 2dip, LayoutPanel.Width - 10dip,40dip)



End Sub

Sub Child1_LayoutCreator(LayoutName As String, LayoutPanel As Panel)


LayoutPanel.Color = Colors.White

'---------------------------Cabecalho----------------------------------------
Dim PanelTitle As Panel
PanelTitle.Initialize("VerDetalhe")
Dim cd As ColorDrawable
'cd.Initialize(Colors.RGB(245,245,245), 7dip)
cd.Initialize(Colors.RGB(245,245,245), 7dip)
PanelTitle.Background = cd
LayoutPanel.AddView(PanelTitle, 0dip, 0dip, LayoutPanel.Width-2dip, 35dip)

cvsDescricao.Initialize(PanelTitle)


Dim chkValidar As CheckBox
chkValidar.Initialize("chkValidar")
chkValidar.Gravity = Gravity.TOP
LayoutPanel.AddView(chkValidar, LayoutPanel.Width -40dip, 2dip, 60dip ,60dip)


'-----------------------------------------------------------------------------------'
End Sub

Sub Parent_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)

Dim Repositorio As String = SaveState.lstLogsCommits.Get(ItemID)
'
' '--------------------------------------------Cabecalho-----------------------------------------------

Dim Rep As Label = LayoutPanel.GetView(1)
Dim iv As ImageView = LayoutPanel.GetView(2)

Rep.Text = Repositorio


If ULV.IsExpanded(ItemID) Then
iv.Bitmap = LoadBitmap(File.DirAssets,"iconUp.png")
Else
iv.Bitmap = LoadBitmap(File.DirAssets,"iconDown.png")
End If

iv.Gravity = Gravity.FILL


'--------------------------------------------------------------------------------------------------------------



End Sub


Sub Child1_ContentFiller(ItemID As Long, LayoutName As String, LayoutPanel As Panel, Position As Int)

Dim LogCommit As eLogCommit
LogCommit.Initialize

If ItemID Mod ChildrenMultiple <= SaveState.lstLogsCommitsDetalhe.Size Then
LogCommit = SaveState.lstLogsCommitsDetalhe.Get(ItemID Mod ChildrenMultiple)
End If

'--------------------------------------------Cabecalho-----------------------------------------------
Dim pnl As Panel = LayoutPanel.GetView(0)
Dim lblUtilizador As Label = LayoutPanel.GetView(1)
Dim lblDataHora As Label = LayoutPanel.GetView(2)
Dim chkValidar As CheckBox = LayoutPanel.GetView(3)
Dim lblDescricao As Label = LayoutPanel.GetView(4)
Dim lblInfoIncidente As ImageView = LayoutPanel.GetView(5)
Dim lblPasta As Label = LayoutPanel.GetView(7)

pnl.Tag = ItemID Mod ChildrenMultiple

If LogCommit.Validado Then
pnl.Background = cdValidado
Else
pnl.Background = cdNaoValidado
End If

lblUtilizador.Text = LogCommit.Utilizador
lblDataHora.Text = LogCommit.strDataHora


chkValidar.Checked = LogCommit.Validado

chkValidar.Tag = ItemID Mod ChildrenMultiple


'--------------------------------------------------------------------------------------------------------------


End Sub

Sub chkValidar_CheckedChange(Checked As Boolean)

Dim chk As CheckBox
chk = Sender


If chk.Tag <> Null AND IsNumber(chk.Tag) Then

Dim ValidarCommit As eLogCommit = SaveState.lstLogsCommitsDetalhe.Get(chk.Tag)

ValidarCommit.Validado = Checked

ULV.RefreshContent


End If

End Sub
Please use email to ask support and send your code. I try to keep this thread for contacts and general information.
 

Rusty

Well-Known Member
Licensed User
Longtime User
I've implemented your library in my code. Basically, I'm using it (for example) to list all the US states and protectorates so someone can select their state.
I would like to "pre-select" the state based upon their geolocation. this works well, but when I select a state toward the bottom of the 50+ item list, it scrolls from the first item to the last. This can take a couple seconds.
I'd like to show the 5 items around the selected state without having is scroll all the items.
for example: Tennessee is item 45 (or so)
I would like to show items 43, 44, 45, 46 and 47, without scrolling all the previous items.
is there a way to load the entire list with50+ items and then display the above mentioned items without it having to scroll the entire list?
thanks,
Rusty
 

Informatix

Expert
Licensed User
Longtime User
I've implemented your library in my code. Basically, I'm using it (for example) to list all the US states and protectorates so someone can select their state.
I would like to "pre-select" the state based upon their geolocation. this works well, but when I select a state toward the bottom of the 50+ item list, it scrolls from the first item to the last. This can take a couple seconds.
I'd like to show the 5 items around the selected state without having is scroll all the items.
for example: Tennessee is item 45 (or so)
I would like to show items 43, 44, 45, 46 and 47, without scrolling all the previous items.
is there a way to load the entire list with50+ items and then display the above mentioned items without it having to scroll the entire list?
thanks,
Rusty
Use JumpTo and set the Smoothly parameter to False. For your example, you can jump to the item #43 and call EnsureVisibility for the item #45.
 

Informatix

Expert
Licensed User
Longtime User
I'm working on a new version of ULV and, contrary to what I did before, the link for the new version won't be sent by email. You are too numerous now and I don't want to invest in a bulk emailing software or service. So I will inform you here and in the announcement thread of the new version availability. You will get it with the same link and password as for v4.01.
 

Rusty

Well-Known Member
Licensed User
Longtime User
Thanks for the update.
I downloaded it and the version is still set to 4.01, is that correct?
Rusty
 

Douglas Farias

Expert
Licensed User
Longtime User
@Informatix
1° why i have this error @on the image
sometimes give me error, sometimes no, i dont understand
i m using your explorer sample, with square image, the problem is when go load the image

sometimes give erro on this line
B4X:
DoEvents
B4X:
Private Sub CommonExplorer
    ulvFiles.FastScroller(FastScrollEnabled)

    Selection.Canceled = True
    Selection.ChosenPath = ""
    Selection.ChosenFile = ""
    edtFilename.RequestFocus

    Do While WaitUntilOK
        ' Main loop - we wait until the OK btn is pressed or the back key is used
        DoEvents
    Loop

    ulvFiles.ClearContent

    pnlBlocker.RemoveView
    pnlBlocker = Null
End Sub


sometimes here
B4X:
Return BmpPlus.ReduceColors(SrcBmp)
B4X:
Public Sub ProcessBitmap(SrcBmp As Bitmap, FinalSize As Int, Squared As Boolean, Rotated As Boolean, RemoveTransparency As Boolean) As Bitmap
    Dim r As Reflector
    r.Target = SrcBmp
    Dim HasAlpha As Boolean = r.RunMethod("hasAlpha")
    If Squared Then
        SrcBmp = SquareBmp(SrcBmp, FinalSize)
    Else
        If Rotated Then
            SrcBmp = RotateBmp(SrcBmp, FinalSize, False)
        Else
            SrcBmp = RescaleBmp(SrcBmp, FinalSize)
        End If
    End If
    If RemoveTransparency OR (Not(HasAlpha) AND Not(Rotated)) Then
        Return BmpPlus.ReduceColors(SrcBmp)
    Else
        Return SrcBmp
    End If
End Sub

note: i dont make any change at your class code

to open the explorer im using
B4X:
Sub btenviarimagens_Click
    dlgFileExpl.Initialize(Activity, File.DirRootExternal, ".png,.jpg,.jpeg,.bmp", False, False, "Enviar")
    dlgFileExpl.FastScrollEnabled = True
    dlgFileExpl.Ellipsis = True
    dlgFileExpl.Editable = False
    dlgFileExpl.ExplorerMulti2(False)
    If Not(dlgFileExpl.Selection.Canceled OR dlgFileExpl.Selection.ChosenFile = "") Then
        Msgbox("Selection:" & CRLF & "Folder=" & dlgFileExpl.Selection.ChosenPath & CRLF & "File(s)=" & dlgFileExpl.Selection.ChosenFile, "Your choice")
    End If
End Sub

2° How to get the list of selected itens? your example give the names, but not in a list it is string, how to get the list of path and file names?
i cant make question for u, my donation is not a total but can i give me only this help?
 

Attachments

  • Sem título.png
    Sem título.png
    201.6 KB · Views: 203
Last edited:

Informatix

Expert
Licensed User
Longtime User
@Informatix
1° why i have this error @on the image
sometimes give me error, sometimes no, i dont understand
i m using your explorer sample, with square image, the problem is when go load the image

sometimes give erro on this line
B4X:
DoEvents
B4X:
Private Sub CommonExplorer
    ulvFiles.FastScroller(FastScrollEnabled)

    Selection.Canceled = True
    Selection.ChosenPath = ""
    Selection.ChosenFile = ""
    edtFilename.RequestFocus

    Do While WaitUntilOK
        ' Main loop - we wait until the OK btn is pressed or the back key is used
        DoEvents
    Loop

    ulvFiles.ClearContent

    pnlBlocker.RemoveView
    pnlBlocker = Null
End Sub


sometimes here
B4X:
Return BmpPlus.ReduceColors(SrcBmp)
B4X:
Public Sub ProcessBitmap(SrcBmp As Bitmap, FinalSize As Int, Squared As Boolean, Rotated As Boolean, RemoveTransparency As Boolean) As Bitmap
    Dim r As Reflector
    r.Target = SrcBmp
    Dim HasAlpha As Boolean = r.RunMethod("hasAlpha")
    If Squared Then
        SrcBmp = SquareBmp(SrcBmp, FinalSize)
    Else
        If Rotated Then
            SrcBmp = RotateBmp(SrcBmp, FinalSize, False)
        Else
            SrcBmp = RescaleBmp(SrcBmp, FinalSize)
        End If
    End If
    If RemoveTransparency OR (Not(HasAlpha) AND Not(Rotated)) Then
        Return BmpPlus.ReduceColors(SrcBmp)
    Else
        Return SrcBmp
    End If
End Sub

note: i dont make any change at your class code

to open the explorer im using
B4X:
Sub btenviarimagens_Click
    dlgFileExpl.Initialize(Activity, File.DirRootExternal, ".png,.jpg,.jpeg,.bmp", False, False, "Enviar")
    dlgFileExpl.FastScrollEnabled = True
    dlgFileExpl.Ellipsis = True
    dlgFileExpl.Editable = False
    dlgFileExpl.ExplorerMulti2(False)
    If Not(dlgFileExpl.Selection.Canceled OR dlgFileExpl.Selection.ChosenFile = "") Then
        Msgbox("Selection:" & CRLF & "Folder=" & dlgFileExpl.Selection.ChosenPath & CRLF & "File(s)=" & dlgFileExpl.Selection.ChosenFile, "Your choice")
    End If
End Sub

2° How to get the list of selected itens? your example give the names, but not in a list it is string, how to get the list of path and file names?
i cant make question for u, my donation is not a total but can i give me only this help?
The Explorer demo doesn't do much to handle the OutOfMemory error. It's probably what you get with very large pictures.
How to get the list of selected items is demonstrated in the example and can be seen just above in the copied lines (dlgFileExpl.Selection...).
 

Douglas Farias

Expert
Licensed User
Longtime User
the file list i have it working now, i make a list under my main and i add itens on this.
but the images i dont know to fix, can you fix this pls? i have buy the ulv only for this explorer pls *-*
 

Informatix

Expert
Licensed User
Longtime User
The new version (4.02) is online. The filename, the link and the password do not change, but the contents is new.
This version requires Java 7 (check your Tools/Configure Paths/javac.exe).

Changelog:
- The state of the fast scroller is now properly recognized under Lollipop;
- I fixed a bug with layout names in some languages;
- I added the GetRelativeIndexForID function;
- I brought minor improvements to examples.
 

Douglas Farias

Expert
Licensed User
Longtime User
Sorry but you got a special offer with no support.
ok but this is not a suport, is your example of your lib, i dont make any change and give me error on your example, i have buy for this work like the images at the 1° post.
i have tested now at + 3 devices and i get same error in your sample explorer. can you try fix this in your examples pls, is not a suport for me , its a suporte for you and your lib
 

Informatix

Expert
Licensed User
Longtime User
ok but this is not a suport, is your example of your lib, i dont make any change and give me error on your example, i have buy for this work like the images at the 1° post.
i have tested now at + 3 devices and i get same error in your sample explorer. can you try fix this in your examples pls, is not a suport for me , its a suporte for you and your lib
This example works fine on all devices (including exotic ones) and OS I have (from Gingerbread to Lollipop, including FireOS) so unless you explain me how to reproduce your issue, for me there's no issue. Running the demo does not trigger any error, even after looking to all the pictures on the device. The only known problem is with very very large pictures. You may encounter an OutOfMemory error but you have a few ways to address this issue (I don't do anything for that in the example because that's not the purpose of the example and the case is very unlikely to happen; that should never happen with the pictures taken by the camera of the device because the device has usually enough RAM to display these pictures).
 
Top