B4A Library CustomListView - A flexible list based on ScrollView

Discussion in 'Additional libraries, classes and official updates' started by Erel, Jul 15, 2012.

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

    fredo Active Member Licensed User

    Did you manage to make a Drag&Drop between Customlistviews possible?
     
  2. JakeBullet70

    JakeBullet70 Well-Known Member Licensed User

    Never did.
     
    fredo likes this.
  3. Erel

    Erel Administrator Staff Member Licensed User

    V1.50 has been released. See first post for more information.
     
  4. LucaMs

    LucaMs Expert Licensed User

    Is the module (.bas) attached the source of the library? It is commented with "version: 1.20"
     
    zingo likes this.
  5. Erel

    Erel Administrator Staff Member Licensed User

    It was the correct module with the wrong version comment. I've fixed it.
     
    zingo likes this.
  6. LucaMs

    LucaMs Expert Licensed User

    I had supposed that, seeing this:

    Type=Class
    Version=6.31

    ;)
     
    Erel likes this.
  7. Anser

    Anser Well-Known Member Licensed 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

    Code:
    '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

    Code:
    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(
    0xFF7EB4FA2dip)
    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
    Code:
    '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-1dip100%x1dip)
    So the Sub looks as follows
    Code:
    '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, 
    00, 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-1dip100%x1dip)
               
        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: Nov 2, 2016
    SandroB4A likes this.
  8. Erel

    Erel Administrator Staff Member Licensed 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.
     
  9. Anser

    Anser Well-Known Member Licensed User

    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.;)
     
  10. Scotter

    Scotter Active Member Licensed User

    Found the bug. Simple mis-spelling.
    Sorry.
     
    Last edited: Nov 22, 2016
  11. DonManfred

    DonManfred Expert Licensed User

    1. You should create a NEW Thread in the questions forum for EACH question you have
    2. Use code tags when posting code!
     
    Scotter and Mahares like this.
  12. luke2012

    luke2012 Well-Known Member Licensed User

    Hi all,
    is there a similar view for B4i?
     
  13. inakigarm

    inakigarm Well-Known Member Licensed User

    Erel likes this.
  14. Erel

    Erel Administrator Staff Member Licensed User

  15. iwanmahe

    iwanmahe New Member Licensed User

    Hi all......
    I want to know the top item index, after scrolling. how to do it?
     
  16. Erel

    Erel Administrator Staff Member Licensed User

    Please start a new thread for this in the questions forum.
     
  17. ilan

    ilan Expert Licensed 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
     
  18. Erel

    Erel Administrator Staff Member Licensed User

    I've updated the library files. The latest version is 1.60.
     
  19. fbritop

    fbritop Active Member Licensed 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
     
  20. Erel

    Erel Administrator Staff Member Licensed 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.
     
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