CustomListView - A flexible list based on ScrollView

Status
Not open for further replies.

Anser

Well-Known Member
Licensed User
Longtime User
I have used CustomListView extensively in my App. Its a very useful CLASS.

I had experienced few limitations with the previous version of CustomListView. To overcome the limitations, referring the suggestions in the forums, I had modified few lines in the previous version of the CustomListView Class

I am trying to list from my memory the limitations (as an app developer that I faced) and it's solutions .

  • There was an issue with the Hide and Show of FAB (Floating Action Button) when used along with the CustomListView ie when the CLV is scrolled. To resolve/overcome this limitation, as per Erel's and Corwin's suggestion, I added the following Sub to the CustomListView Class. This resolved the FAB Hide/Display while scrolling CustomListView

B4X:
'Added the following sub as per Corwin and Erel's suggestion to support FAB
' hiding and showing while CustomListView is scrolled
Sub sv_ScrollChanged(Position As Int)
    CallSub2(CallBack, EventName & "_ScrollChanged", Position)
End Sub

  • If the CustomListView does not have enough contents to fill the entire screen length, the blank area was filled with a weird gray color. This used to cause aesthetic issues in the app (depends on the themes/color schemes used in the app). The app developer had no options left other than modifying the source code of the Class CustomListView. So to to resolve the gray backcolor issue when there are not enough contents in CustomListView to fill the entire screen length, I made the changes in the Sub Initialize and Sub InsertAt
Another user named @Prosg also had the same issue and I just followed his suggestion and modified the following Sub's in the CustomListView Class. This resolved the above described issue.

Sub's Modified:-
Public Sub Initialize
Public Sub InsertAt

B4X:
Public Sub Initialize (vCallback As Object, vEventName As String)
    EventName = vEventName
    CallBack = vCallback
    sv.Initialize2(0, "sv")
    items.Initialize
    panels.Initialize

    'these defaults will be used when the view is added by code
    dividerHeight = 2dip
    'The next line of code is commented by as per the user prosg in the following thread
             'https://www.b4x.com/android/forum/threads/customlistview-background-color.53363/#post-334402
    'sv.Color = 0xFFD9D7DE
    sv.Color = Colors.White 'This was added by Anser
    DefaultTextColor = Colors.White
    DefaultTextSize = 16
    DefaultTextBackgroundColor = Colors.Black
    DefaultTextBackground = Null
    PressedDrawable.Initialize(0xFF7EB4FA, 2dip)
End Sub

At the bottom of the following sub
Public Sub InsertAt(Index As Int, Pnl As Panel, ItemHeight As Int, Value As Object)

I added the following lines
B4X:
    'The next 4 lines of code is added by Anser as per the user prosg in the following thread
    'https://www.b4x.com/android/forum/threads/customlistview-background-color.53363/#post-334402
    'This will resolve the gray backcolor issue when there are not enough contents in CustomListView to fill the entire screen length
  Dim lblDivider As Label
  lblDivider.Initialize("")
  lblDivider.Color = Colors.RGB(217,215,222)
  p.AddView(lblDivider, 0,p.Height-1dip, 100%x, 1dip)

So the Sub looks as follows
B4X:
'Adds a custom item at the specified index.
Public Sub InsertAt(Index As Int, Pnl As Panel, ItemHeight As Int, Value As Object)

    Dim sd As StateListDrawable
    sd.Initialize
    sd.AddState(sd.State_Pressed, PressedDrawable)
    sd.AddCatchAllState(Pnl.Background)

    'create another panel to handle the click event
    Dim p As Panel
    p.Initialize("panel")
    p.Background = sd
    Dim cd As ColorDrawable
    cd.Initialize(Colors.Transparent, 0)
    Pnl.Background = cd
    p.AddView(Pnl, 0, 0, sv.Width, ItemHeight)
    p.Tag = Index

    If Index = items.Size Then
        items.Add(Value)
        panels.Add(p)
        Dim top As Int
        If Index = 0 Then top = dividerHeight Else top = sv.Panel.Height
        sv.Panel.AddView(p, 0, top, sv.Width, ItemHeight)
    Else
        Dim top As Int
        If Index = 0 Then
            top = dividerHeight
        Else
            Dim previousPanel As Panel
            previousPanel = panels.Get(Index - 1)
            top = previousPanel.top + previousPanel.Height + dividerHeight
        End If

        Dim p2 As Panel
        For i = Index To panels.Size - 1
            p2 = panels.Get(i)
            p2.top = p2.top + ItemHeight + dividerHeight
            p2.Tag = i + 1
        Next
        items.InsertAt(Index, Value)
        panels.InsertAt(Index, p)
        sv.Panel.AddView(p, 0, top, sv.Width, ItemHeight)
    End If

    'The next 4 lines of code is added by Anser as per the user prosg in the following thread
    'https://www.b4x.com/android/forum/threads/customlistview-background-color.53363/#post-334402
    'This will resolve the gray backcolor issue when there are not enough contents in CustomListView to fill the entire screen length
    Dim lblDivider As Label
    lblDivider.Initialize("")
    lblDivider.Color = Colors.RGB(217,215,222)
    p.AddView(lblDivider, 0,p.Height-1dip, 100%x, 1dip)
           
    sv.Panel.Height = sv.Panel.Height + ItemHeight + dividerHeight
    If items.Size = 1 Then sv.Panel.Height = sv.Panel.Height + dividerHeight
End Sub

I would like to know how to address the above said issues with the New CustomView Library. I do not know whether the above said limitations are taken care in the new Library ? Requesting your suggestion on this.

Regards

Anser
 
Last edited:

Anser

Well-Known Member
Licensed User
Longtime User
Use the source code instead of the library. There aren't many changes and it shouldn't be difficult to apply the changes you did to the new version. You can use a tool such as WinMerge (http://winmerge.org/?lang=en) to compare the two versions.
OK. I didn't notice that the source code was also there, I blindly jumped into the conclusion that from this version onward only the lib will be available.;)
 

DonManfred

Expert
Licensed User
Longtime User
1. You should create a NEW Thread in the questions forum for EACH question you have
2. Use code tags when posting code!
 

ilan

Expert
Licensed User
Longtime User
hi

i have downloaded the lib file but i still see in the lib tab v1.50. but it says that the latest version is v1.60
is the lib file in first post v1.6 or v1.5?

thanx
 

fbritop

Active Member
Licensed User
Longtime User
Is there any difference when using the customlistview in debugging/release mode?.

Cannot seem to find the bug, I have a CLV that I add 280 panels. If I try it on debug mode, it takes 3.5 sec average. If I run it in release mode, it takes 14.9 sec.

Has someone experimented something like this?

Thanks
FBP
 

ilan

Expert
Licensed User
Longtime User
Press on Ctrl + P (clean project) and then run your program. It will cause the compiler to make a full deployment and will run faster in debug mode.

But he is saying that in RELEASE mode it runs much slower. It's weird o_O
 
Status
Not open for further replies.
Top