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

Status
Not open for further replies.

npsonic

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.

B4X:
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
           'visible+
           If p.NumberOfViews = 0 Then
               Dim cd As CardData = CLV1.GetValue(i)
               p.LoadLayout("Card1")
               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
               CLV1.ResizeItem(p,300dip)
           End If
       Else
           'not visible
           If p.NumberOfViews > 0 Then
               p.RemoveAllViews '<--- remove the layout
           End If
       End If
   Next
End Sub
 

npsonic

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.

B4X:
'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
    p.RemoveViewFromParent
    ReplaceAt(Index, p, ItemHeight, item.Value)
End Sub
 

Dadaista

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

B4X:
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
B4X:
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:)
 

DonManfred

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

Dadaista

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
B4X:
clv4.JumpToItem (clv4.LastVisibleIndex)
. Never mind!!:)

Thx!!:)
 

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?
 

Erel

Administrator
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.
 
Status
Not open for further replies.
Top