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

Status
Not open for further replies.
Update: As several other libraries depend on xCustomListView library, it is no longer recommended to use the code module. Use the library instead. There are several extension classes that add more features to xCLV. They are listed at the end of this post.

Video tutorial:


xCustomListView is an implementation of CustomListView based on XUI library. It provides all the features of the original CustomListView and it is compatible with B4A, B4J and B4i.

SS-2017-09-27_11.15.59.png
SS-2017-09-27_11.16.26.png
SS-2017-09-27_11.16.50.png


SS-2017-12-27_16.20.44.png


This class replaces the platform specific CustomListView classes. It is recommended to use this one for new projects.

Change log:

- V1.74 - Fixes a bug with JumpToItem (B4i).
- V1.72 (B4A only) - Fixes an issue where the designer typeface is not set when calling AddTextItem.
- V1.71 (B4i only) - Fixes an issue related to iOS 9- devices.
- V1.70 - ItemLongClick event (right click in B4J).
- V1.68 - Fixes a bug with ResizeItem / ReplaceAt and lists with single item.
- PressedColor is now a public field.
- Setting the PressedColor to a transparent color disables the item click color animation. This is useful if you want to replace it with your own implementation.
- V1.66 - Improves the text measurement of text items in B4J.
- V1.65 - Fixes an issue in B4i only where the CSBuilder colors were ignored.
- V1.64 - Fixes an issue with ScrollToItem / JumpToItem in B4i.
- V1.63 - Bug fixes, Refresh method to force VisibleRangeChanged to be raised, several private subs are now public, designer property to hide the scroll bar.
- V1.54 - Allows using CSBuilder with AddTextItem in B4i (it is also supported in B4A).
- V1.53 - Fixes an issue with VisibleRangeChanged event and CLV.Clear
- V1.52 - Fixes an issue with CLV.RemoveAt
- V1.51 - Fixes an issue which caused the LastVisibleIndex and FirstVisibleIndex properties to be hidden.

- V1.50 - Large update.
- V1.20 - Adds support for horizontal orientation.
Set it in the designer.
Add items like this:
B4X:
clv2.Add(CreateListItem($"Item #${i}"$, 160dip, clv2.AsView.Height), $"Item #${i}"$)
'Instead of
'clv2.Add(CreateListItem($"Item #${i}"$, clv2.AsView.Width, 160dip), $"Item #${i}"$)

Don't use the source code. Use the preinstalled xCustomListView library instead.
Libraries such as XUI Views depend on the library and will not work properly with the module.

Extension classes:

CLVExpandable (B4X) - Allows expanding and collapsing items: https://www.b4x.com/android/forum/t...g-or-collapsing-xcustomlistview-items.106148/
CLVSwipe (B4A and B4i) - Adds swipe actions and swipe to refresh feature: https://www.b4x.com/android/forum/threads/98252/#content
CLVHeader - (B4X) - Adds a nice animated header to the list: https://www.b4x.com/android/forum/t...ted-header-to-xcustomlistview.105343/#content
CLVSelections (B4X) - Adds more selection modes: https://www.b4x.com/android/forum/t...d-selection-modes-for-xcustomlistview.114364/
CLVNested (B4A) - Allows nesting a CLV inside a CLV item: https://www.b4x.com/android/forum/threads/clvnested-allows-nesting-clvs.107742/#content
PreoptimizedCLV (B4X) - Lazy loading + fast scroll extension: https://www.b4x.com/android/forum/t...loading-extension-for-xcustomlistview.115289/

 

Attachments

  • CustomListView.bas
    19.8 KB · Views: 1,696
  • CLVExample.zip
    20.2 KB · Views: 2,231
Last edited:

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 :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
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.
Top