B4A Library [B4X] [XUI] xCustomListView - cross platform CustomListView

Not open for further replies.


Active Member
Licensed User
There is some funky going on with the ResizeItem method. If you want to resize item, it will crash the app.

Error can be created with the LazyLoading example. Changed code attached. When panel becomes in visible range I would want to resize height, but now it produces error.

Sub CLV1_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
   Dim ExtraSize As Int = 20
   For i = 0 To CLV1.Size - 1
       Dim p As B4XView = CLV1.GetPanel(i)
       If i > FirstIndex - ExtraSize And i < LastIndex + ExtraSize Then
           If p.NumberOfViews = 0 Then
               Dim cd As CardData = CLV1.GetValue(i)
               lblTitle.Text = cd.Title
               lblContent.Text = cd.Content
               SetColorStateList(lblAction1, xui.Color_LightGray, lblAction1.TextColor)
               SetColorStateList(lblAction2, xui.Color_LightGray, lblAction2.TextColor)
               ImageView1.SetBitmap(xui.LoadBitmapResize(File.DirAssets, cd.BitmapFile, ImageView1.Width, ImageView1.Height, True))
               'When panel is resized it will crash the app
           End If
           'not visible
           If p.NumberOfViews > 0 Then
               p.RemoveAllViews '<--- remove the layout
           End If
       End If
End Sub


Active Member
Licensed User
Okay, I found error.

When we are resizing the panel, value from item list is forwarded into ReplaceAt method.
That shouldn't be like that. Items list contains only CLVItems so we should pass only value from CLVItem.

Fixed ResizeItem method attached.

'Changes the height of an existing item.
Public Sub ResizeItem(Index As Int, ItemHeight As Int)
    Dim p As B4XView = GetPanel(Index)
    Dim item As CLVItem = items.Get(Index)
    Dim parent As B4XView = p.Parent
    p.Color = parent.Color
    ReplaceAt(Index, p, ItemHeight, item.Value)
End Sub


Active Member
Licensed User
You should update to most recent version 1.53 and copy paste ResizeItem method. Change affects all platforms B4i, B4J and B4A.
0K. Did it!

thx @npsonic :)

Now I have an error after replacing the library

Sub CargaItemLista
    Dim i As Int
    i = clv4.GetSize + 1
    clv4.Add(CreateListItem(i, clv4.AsView.Width, 60dip), i)
    clv4.JumpToItem (i) ' IN THIS LINE
End Sub
Log says
customlistview_getitem (B4A line: 111)
Return items.Get(Index)
java.lang.IndexOutOfBoundsException: Invalid index 1, size is 1
    at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
    at java.util.ArrayList.get(ArrayList.java:308)
    at anywheresoftware.b4a.objects.collections.List.Get(List.java:117)
    at com.dbsaiz.caja.venta.free.customlistview._getitem(customlistview.java:607)
    at com.dbsaiz.caja.venta.free.customlistview._finditemoffset(customlistview.java:552)
    at com.dbsaiz.caja.venta.free.customlistview._jumptoitem(customlistview.java:1164)
    at com.dbsaiz.caja.venta.free.main._cargaitemlista(main.java:5852)
    at com.dbsaiz.caja.venta.free.main._buttoncheck_click(main.java:4886)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:186)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:170)
    at anywheresoftware.b4a.BA.raiseEvent(BA.java:166)
    at anywheresoftware.b4a.objects.ViewWrapper$1.onClick(ViewWrapper.java:80)
    at android.view.View.performClick(View.java:4787)
    at android.view.View$PerformClick.run(View.java:19873)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5254)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:903)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:698)
Same error in B4J obviously:)


Licensed User
clv4.JumpToItem (i-1)
Based on the error you want access item 1 (index 0) but your are using 1 here.


Active Member
Licensed User
Yes @DonManfred but the line did not fail before replace the lib :confused:.. Why???? I do not knowo_Oo_O

I will replace that line by this one
clv4.JumpToItem (clv4.LastVisibleIndex)
. Never mind!!:)


Carlos marin

Active Member
Licensed User
hello, I'm trying to use this new CustomListView, I have some images on a server and I can not use xui to adjust them in my image view anyone knows how to do it, use this CustomListView loading images from a server on the web?


Staff member
Licensed User
V1.66 released. It improves the text measurement of text items in B4J.

The library will be included in B4J v7.00.
Not open for further replies.