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

Discussion in 'Additional libraries, classes and official updates' started by Erel, Oct 1, 2017.

Thread Status:
Not open for further replies.
  1. Erel

    Erel Administrator Staff Member Licensed User

    You are correct. It is fixed in v1.52 that was uploaded to the first post.
     
  2. npsonic

    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.

    Code:
    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
     
  3. npsonic

    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.

    Code:
    '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
     
    Claudio Oliveira likes this.
  4. Dadaista

    Dadaista Member Licensed User

    Hi

    Should I replace the library in B4J as well?
     
  5. npsonic

    npsonic 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.
     
    Dadaista likes this.
  6. Dadaista

    Dadaista Member Licensed User

    0K. Did it!

    thx @npsonic :)


    Now I have an error after replacing the library

    Code:
    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
    Code:
    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:)
     
  7. DonManfred

    DonManfred Expert Licensed User

    Maybe
    Code:
    clv4.JumpToItem (i-1)
    Based on the error you want access item 1 (index 0) but your are using 1 here.
     
  8. Dadaista

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

    Thx!!:)
     
  9. Carlos marin

    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?
     
  10. Erel

    Erel Administrator Staff Member Licensed User

    This thread is closed. Please start a new thread for any question you have.
     
  11. Erel

    Erel Administrator Staff Member Licensed User

    V1.63 released. See first post.
     
  12. Erel

    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.
     
    luke2012 likes this.
  13. Erel

    Erel Administrator Staff Member Licensed User

    - V1.70 - ItemLongClick event (right click in B4J).
     
    luke2012, Dadaista, Myr0n and 2 others like this.
Thread Status:
Not open for further replies.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice