B4J Question Tree List

MHND

New Member
Good Morning,
how can i draw tree in b4j ?
like this one and I need to fill it by data from database
1709105027400.png
 

Alexander Stolte

Expert
Licensed User
Longtime User
Upvote 0

William Lancee

Well-Known Member
Licensed User
Longtime User
I had some time today. Project is attached.

hTree.png


B4X:
Private Sub B4XPage_Created (Root1 As B4XView)
    Root = Root1
    cv.Initialize(Root)
    Sleep(0)
    drawGrid(20, 3)
    Dim treeData As List =    CreateList(Array( _
            CreateMap("text": "Item 1", "row": 10, "col": 0, "children": CreateList(Array( _
                    CreateMap("text": "Item 1-1", "row": 8, "col": 1,"children": CreateList(Array( _
                            CreateMap("text": "Item 1-1-1", "row": 3, "col": 2), _
                            CreateMap("text": "Item 1-1-2", "row": 4, "col": 2)) _
                    )), _
                    CreateMap("text": "Item 1-2", "row": 9, "col": 1, "children": CreateList(Array( _
                            CreateMap("text": "Item 1-2-1", "row": 9, "col": 2), _
                            CreateMap("text": "Item 1-2-2", "row": 10, "col": 2)) _
                    )), _
                    CreateMap("text": "Item 1-3", "row": 10, "col": 1, "children": CreateList(Array( _
                            CreateMap("text": "Item 1-3-1", "row": 15, "col": 2)) _
                    ))) _      
            )) _
    ))
           
    drawTree(treeData, "")
End Sub

Private Sub drawTree(tree As List, tabs As String)
    tabs = tabs & TAB
    Dim connectCount As Int
    For Each item As Map In tree
        Dim text As String = item.Get("text")
        Dim row As Int = item.Get("row")
        Dim col As Int = item.Get("col")
        drawText(text, row, col, tabs)
        If item.ContainsKey("children") Then
            Dim children As List = item.Get("children")
            connectCount = connectCount + 1
            connect(connectCount, row, col, children.Get(0), True)
            connect(connectCount, row, col, children.Get(children.Size -1), False)
            drawTree(children, tabs)
        End If
    Next
End Sub
 

Attachments

  • hTree.zip
    21.1 KB · Views: 100
Last edited:
Upvote 1
Top