Android Question PCLV AddItem

hanyelmehy

Well-Known Member
Licensed User
Longtime User
When Add the items with PCLV.AddItem. You need to pass the item size (height for vertical lists and width for horizontal lists)
i have items with differnt heights ,any idea how to handel this
in CLV_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int) i try ti change panel hight ,but its seem have no effect
 

Brian Dean

Well-Known Member
Licensed User
Longtime User
You need to pass the item size . . . . . i have items with differnt heights ,any idea how to handel this
Yes - when you add the item to the PCLV enter the height that you want that item to have. It is not necessary for all items to be the same.

You can retrieve the panel size in CLV_VisibleRangeChanged( ) and add a new panel with a layout :
B4X:
Sub clvBooks_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
  For Each i As Int In pCLV.VisibleRangeChanged(FirstIndex, LastIndex)
    Dim item As CLVItem = clvTarget.GetRawListItem(i)
    Dim pnl As B4XView = xui.CreatePanel("")
    item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
    pnl.LoadLayout("panelLayout")
    . . . .
    . . . .
  Next
End Sub
 
Upvote 0

hanyelmehy

Well-Known Member
Licensed User
Longtime User
Yes - when you add the item to the PCLV enter the height that you want that item to have. It is not necessary for all items to be the same.

You can retrieve the panel size in CLV_VisibleRangeChanged( ) and add a new panel with a layout :
B4X:
Sub clvBooks_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
  For Each i As Int In pCLV.VisibleRangeChanged(FirstIndex, LastIndex)
    Dim item As CLVItem = clvTarget.GetRawListItem(i)
    Dim pnl As B4XView = xui.CreatePanel("")
    item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
    pnl.LoadLayout("panelLayout")
    . . . .
    . . . .
  Next
End Sub
Thank you for your answer ,but i was try to change item.Panel.Height to other valur not work for me ,did you test that before ?
 
Last edited:
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
did you test that before ?
Yes, I did test it by modifying a similar program that I have been working on. I am away from my PC but I can send you a demo later. However I think you are not doing what I recommended in my post.
... try to change item.Panel.Height
In my example I do NOT change the item.panelHeight. The item.Panel.Height will have been set when you added the item to the pCLV -
B4X:
For Each w As whatever In datalist        ' Add data objects to pCLV
    ' Set item height to the height that you want
    pCLV.AddItem(height_value, xui.Color_White, w)
Next
Then when you retrieve the "item" later you can retrieve the height. But you cannot load a layout to item.Panel (or at least, I could not). Instead you add a panel to cover item.Panel and load your layout to that - look again at the code in my earlier post.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
Here is the demo code :
B4X:
Sub setup
    pCLV.Initialize(Me, "pclv", clvDemo)
    For i = 0 To 99
        pCLV.AddItem(Rnd(200, 480), tints(i Mod 4), i)
    Next
    pCLV.Commit
End Sub

Sub clvDemo_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In pCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = clvDemo.GetRawListItem(i)
        Dim pnl As B4XView = xui.CreatePanel("")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        pnl.LoadLayout("item")
    Next
End Sub

Here is the result :

Demo.jpg


Here is the project :
 

Attachments

  • pCLV Demo.zip
    10.5 KB · Views: 52
Last edited:
Upvote 0

hanyelmehy

Well-Known Member
Licensed User
Longtime User
Here is the demo code :
B4X:
Sub setup
    pCLV.Initialize(Me, "pclv", clvDemo)
    For i = 0 To 99
        pCLV.AddItem(Rnd(200, 480), tints(i Mod 4), i)
    Next
    pCLV.Commit
End Sub

Sub clvDemo_VisibleRangeChanged (FirstIndex As Int, LastIndex As Int)
    For Each i As Int In pCLV.VisibleRangeChanged(FirstIndex, LastIndex)
        Dim item As CLVItem = clvDemo.GetRawListItem(i)
        Dim pnl As B4XView = xui.CreatePanel("")
        item.Panel.AddView(pnl, 0, 0, item.Panel.Width, item.Panel.Height)
        pnl.LoadLayout("item")
    Next
End Sub

Here is the result :

View attachment 164959

Here is the project :
Thank you again for your great help! I understand that I can set different heights when using pCLV.AddItem. However, my issue is that the items are created at runtime, and their images are loaded online. Since these images may have varying heights, and the text content can also differ, each item's height becomes dynamic. Pre-calculating all item heights before calling pCLV.AddItem would be challenging in this scenario. For now, I believe the best solution is to set a fixed item height.
 
Upvote 0

Brian Dean

Well-Known Member
Licensed User
Longtime User
. . . items are created at runtime, and their images are loaded online.
Okay - I see the problem. You don't know what size the image will be until the related item is scrolled into view for the first time and the related image is downloaded. That is not a situation that I can remember seeing before, so I cannot suggest an answer. Maybe someone else can.

Edit : Thinking more about this I can see some real difficulties. You can in some circumstances change the size of a CLV item as there is a CLV.ResizeItem(i, size) method. However if you did this within the CLV.VisibleRangeChanged() handler then this could itself change the visible range and, presumably, cause some sort of recursive call to the handler - not something that I would want to encourage.
 
Last edited:
Upvote 0
Top