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
 

npsonic

Active Member
Licensed User
Hi

Should I replace the library in B4J as well?

You should update to most recent version 1.53 and copy paste ResizeItem method. Change affects all platforms B4i, B4J and B4A.
 

Dadaista

Active Member
Licensed User
Longtime 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
 

Dadaista

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

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

Thx!!
 

Carlos marin

Active Member
Licensed User
Longtime 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

B4X founder
Staff member
Licensed User
Longtime User
Example project updated.

CreateListItem is cross platform now:
B4X:
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel
    Dim p As B4XView = xui.CreatePanel("")
    p.SetLayoutAnimated(0, 0, 0, Width, Height)
    p.LoadLayout("CellItem")
    Label1.Text = Text
    Return p
End Sub
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
A cross platform example based on B4XPages and the new DSE feature was uploaded to the first post.

Instead of writing fragile code that relies on the views order, such as:
B4X:
Dim pnl As B4XView = clv2.GetPanel(index)
    Dim lbl As B4XView = pnl.GetView(0)
    Dim chk As B4XView = pnl.GetView(2)
We can now write:
B4X:
Dim pnl As B4XView = clv2.GetPanel(index)
Dim lbl As B4XView = dd.GetViewByName(pnl, "Label1")
Dim chk As B4XView = dd.GetViewByName(pnl, "CheckBox1")

Note that the B4i project requires B4i v8.00. Beta version will be released next week.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…