B4J Question TreeView again

Sergey_New

Well-Known Member
Licensed User
Longtime User
Filled out a map from a hierarchical text file. The map contains the data of each record and its parent. I'm trying to build a TreeView, but I can't get any further than in the example. I understand that recursion is required, but I don’t understand how to do it. Please help.
 

Attachments

  • test.zip
    30.3 KB · Views: 99

moore_it

Well-Known Member
Licensed User
Longtime User
Hi you need to order the map with index and subindex for example :

head = 0
son1 = 0 0
son2 = 0 1
son22 = 0 1 0
son3 = 0 2
etc.

B4X:
Sub fillTree
    For i = 1 To mf.Size
        Dim r As record=mf.Get(i)
        'If r.c1=0 Then
            If r.parent = 0 Then
                Dim ti As TreeItem
                ti.Initialize("ti", r.c2)
            Else if r.parent = 1 Then
                Dim cti As TreeItem
                cti.Initialize("cti", "My father " & ti.Text)
                ti.Children.Add(cti)
            Else
                Dim dti As TreeItem
                dti.Initialize("dti", "My brother " & cti.Text)
                cti.Children.Add(dti)
            End If
            tv.Root.Children.Add(ti)
        'End If
    Next
End Sub

try that !
 
Upvote 0

Sergey_New

Well-Known Member
Licensed User
Longtime User
I managed to build a tree. I haven't used recursion, but I would like to.
An example is attached.
 

Attachments

  • test.zip
    4 KB · Views: 90
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…