Android Question PreOptimizedCLV with PCLV.ShowScrollBar = True and empty CustomListView

peacemaker

Expert
Licensed User
Longtime User
Hi, All

If the list of items to show has become empty after selecting from a db - there is a trouble with PreOptimizedCLV that has PCLV.ShowScrollBar = true.
Touching the scrollbar gives error
Error occurred on line: 165 (PreoptimizedCLV)
java.lang.IndexOutOfBoundsException: Index: 0, Size: 0
at java.util.ArrayList.get(ArrayList.java:411)
...
And it's unclear how to avoid it, setting PCLV.ShowScrollBar = false - does not work.
B4X:
    PCLV.Initialize(Me, "PCLV", CustomListView1)
    If curPics.RowCount > 0 Then       
        For i = 1 To curPics.RowCount Step 4
            curPics.Position = i
            PCLV.AddItem(height, xui.Color_White, CreateMyImageData(i))
        Next
        PCLV.ShowScrollBar = True
        PCLV.ExtraItems = 3
        PCLV.Commit
    Else
        PCLV.ShowScrollBar = False
        PCLV.Commit
        ToastMessageShow("Empty list", False)
    End If


Any suggestion ?
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
SOLVED:
Sub B4XSeekBar1_TouchStateChanged (Pressed As Boolean)
    If items.Size = 0 Then Return
    ...
 

Attachments

  • PreoptimizedCLV.b4xlib
    6.5 KB · Views: 108
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Any suggestion ?

I have a similar code but I use resultset and it works. Here is my code for my case:
B4X:
If rs.RowCount>0 Then
            Do While rs.NextRow
                PCLV.ShowScrollBar = True
                Dim CNT As ColorNameType
                CNT.Initialize
                CNT.LabelText =rs.GetString("ColorName")
                CNT.LabelNum =rs.GetString("ColorNum")
                PCLV.AddItem(75dip, XUI.Color_Magenta, CNT) 
            Loop
        Else
            Log("No records found")
            PCLV.ShowScrollBar = False
        End If
        rs.Close
I thought you are posting a project for us to check, but all you did is post a copy of the Preoptimized lib. That does not help. Note I am using the internal b4xlib 1.21
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I posted the lib, setting PCLV.ShowScrollBar is not enough - PCLV.Commit is also required.
And i have the error at "B4XSeekBar1_TouchStateChanged" event if the list is empty if to touch the seekbar.
 
Last edited:
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
Question also is how to refresh PCLV if CustomListView is reused, refreshed.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
how to refresh PCLV if CustomListView is reused, refreshed.
PCLV is nothing but an extension to xClv. It is automatically refreshed if I understand you correctly.
Have you read these important remarks from Erel:
  • The item layout should have a transparent background.
  • Better to remove AutoScaleAll and set the animation duration to 0 in the item layout.
  • The list should scroll very smoothly in release mode.
  • Make sure that "Show Scrollbar" option is unchecked in CLV custom properties.
  • PCLV.pnlOvarlay is the panel that hides the list when it fast scrolls. PCLV.lblHint is the label that appears. Both can be customized.
  • You can change the seek bar interval by setting PCLV.NumberOfSteps, before calling PCLV.Commit. The default value is 20. Don't set it to be too high as it will be difficult for the user to select a specific point.
in this link.
If you still need help, post your project or wait for Erel to read this post and educate both of us.
 
Upvote 0

peacemaker

Expert
Licensed User
Longtime User
I have solved it also:
B4X:
Sub CreateGallery(group As String)
    MediaManager.Initialize
    MediaManager.MaxImageSize = 150    'max image side size in pixels
    MediaManager.MaxMediaCacheSize = 3000
    CustomListView1.Clear    ' Important_1
    PCLV.ListChangedExternally  ' Important_2 !!!
 
Upvote 0
Top