Android Question SD Treelist save value and load value

mike1967

Active Member
Licensed User
Longtime User
Hello, with SD Treeview using KVS2 library i was able to save the value to files:
code:
    Dim kvs As KeyValueStore
    xui.SetDataFolder("kvs")
    kvs.Initialize(xui.DefaultFolder, "kvs.dat")
    ....
    
    kvs.Put("tree",B4XTree1.TreeToJson)
    Log(kvs.Get("tree"))
Is ther a way to load this value In B4XTree1 after close and reopen the app ?
thanks in advanced
 

Star-Dust

Expert
Licensed User
Longtime User
You can do this if you download the 0.22 version with which I made the tree storage to JSON more complete.

This is the code to repopulate the tree starting from JSON
B4X:
Dim JsonString As String= kvs.Get("tree")
' Save data
File.WriteString(Path,Filename,JsonString )
' Recover data
Dim Tm As Map = JsonString.As(JSON).ToMap

' repopulate
B4XTree1.Clear
ScanMap(Tm,"")

Private Sub ScanMap(M As Map,IDParent As String)
    For Each K As String In M.Keys
        Log(K)
        Dim SubM As Map = M.Get(K)
        Log(SubM)
        If SubM.ContainsKey("Leaf")=False Then
            B4XTree1.AddLeaf(SubM.Get("Name"),SubM.Get("Info"),SubM.Get("ID"),IDParent)
        Else
            B4XTree1.AddBranch(K,SubM.Get("ID"),IDParent,SubM.Get("Symbol"),SubM.Get("Color"))
            ScanMap(SubM.Get("Leaf"),SubM.Get("ID"))
        End If
    Next
End Sub
 
Last edited:
Upvote 2

Star-Dust

Expert
Licensed User
Longtime User
Hello, with SD Treeview using KVS2 library i was able to save the value to files:
code:
    Dim kvs As KeyValueStore
    xui.SetDataFolder("kvs")
    kvs.Initialize(xui.DefaultFolder, "kvs.dat")
    ....
   
    kvs.Put("tree",B4XTree1.TreeToJson)
    Log(kvs.Get("tree"))
Is ther a way to load this value In B4XTree1 after close and reopen the app ?
thanks in advanced
I'd love to know if you've solved it. Thank you
 
Upvote 0

mike1967

Active Member
Licensed User
Longtime User
You can do this if you download the 0.22 version with which I made the tree storage to JSON more complete.

This is the code to repopulate the tree starting from JSON
B4X:
Dim JsonString As String= kvs.Get("tree")
Dim Tm As Map = JsonString.As(JSON).ToMap
B4XTree1.Clear
ScanMap(Tm,"")

Private Sub ScanMap(M As Map,IDParent As String)
    For Each K As String In M.Keys
        Log(K)
        Dim SubM As Map = M.Get(K)
        Log(SubM)
        If SubM.ContainsKey("Leaf")=False Then
            B4XTree1.AddLeaf(SubM.Get("Name"),SubM.Get("Info"),SubM.Get("ID"),IDParent)
        Else
            B4XTree1.AddBranch(K,SubM.Get("ID"),IDParent,SubM.Get("Symbol"),SubM.Get("Color"))
            ScanMap(SubM.Get("Leaf"),SubM.Get("ID"))
        End If
    Next
End Sub
Thanks with this code i solved it
 
Upvote 0
Top