B4J Code Snippet [B4J] [B4A] Expandable CLV with sub-items (similar to a tree)

I needed this and didn't find an existing solution: a CLV whose items
- can be expanded/collapsed (available in @Erel's CLVExpandable)
- and can have sub-items that can be shown or hidden

In the screenshot below, you'll see the arrows that can be used to expand/collapse, and the +/- signs to show/hide sub-items; B4A and B4J projects attached.

Some notes:
- module 'wmCLVEpandable2' is @Erel's with a couple of slight modifications
- to avoid mysterious errors etc, do read the comments in the source code
- I couldn't find a way to make the pane(l)s indent (spent quite some time trying to figure it out), so I worked around that by using multiple layout files
- no external libraries required

Tested with B4A and B4J, no idea what B4I would do or if it even would compile :)

Enjoy !

EDIT: example with a SQLite db attached, which is a lot more meaningful (thanks for asking, @Mahares )

CLVexSub.png
 

Attachments

  • CLVexSub_B4A.zip
    20.8 KB · Views: 93
  • CLVexSub_B4J.zip
    14.1 KB · Views: 95
  • CLVexSub_SQLite.zip
    15.3 KB · Views: 91
Last edited:

Mahares

Expert
Licensed User
Longtime User
Can you post a small B4A project using some real data from a text file or a SQLite table to see how the data is tabulated. Thank you
 

walt61

Active Member
Licensed User
Longtime User
I guess you were thinking along the lines of grouped rows in Excel with subtotals, but that's not what it does: you pass whatever data (and layout - for the expanded part) you like. Think e.g. about something like this:
- the data represent tasks
- any task (incl. sub-tasks) can have sub-tasks
- the expandable/collapsible panel (the one with the 2 big buttons in the example) contains detailed data about a task, like description, start/end dates, etc
 

Mahares

Expert
Licensed User
Longtime User
I guess you were thinking along the lines of grouped rows in Excel with subtotals
No. That is not what I was looking for. Here is a sample text file. How do you incorporate it in your project to show the hierarchy:
Cat1; Cat2; Cat3; Cat4
Tools; Garden Tools; Weed Wackers; Electric
Tools; Garden Tools; Weed Wackers; Gas
Tools; Shop Tools; Vice;
Tools; Shop Tools; Level;
Tools; Shop Tools; Stud Finder;
Tools; Shop Tools; Screw Drivers; Manual
Tools; Shop Tools; Screw Drivers; Power
Tools; Shop Tools; Hammers; Sledge Hammers
Tools; Shop Tools; Hammers; Precision Hammers
Tools; Car Tools; Jack;
Tools; Car Tools; Tire Gauge; Digital Gauge
Tools; Car Tools; Tire Gauge; Analog Gauge

Can you provide a sample project depicting real tasks
 

Mahares

Expert
Licensed User
Longtime User
@walt61, very good work. I have added a couple of very small subs to Walt's class that allow for collapsing or expamding all expandable panels:
B4X:
Public Sub CollapseAll   
    For i=0 To mCLV.Size -1
        ResizeItem(i, True)
    Next
End Sub

Public Sub ExpandAll   
    For i=0 To mCLV.Size -1
        ResizeItem(i, False)
    Next
End Sub
To call them, I added one button to the 'main' layout with default text: 'Expand All ' and put this code in B4XMainPage to toggle
B4X:
Sub btnExpandCollapse_Click
    If btnExpandCollapse.text ="Expand All" Then
        expandable.ExpandAll
        btnExpandCollapse.text ="Collapse All"
    Else if btnExpandCollapse.text ="Collapse All" Then
        expandable.CollapseAll
        btnExpandCollapse.text ="Expand All"
    End If
End Sub
 
Top