Android Question Write 2 map views to a single txt file

aaronk

Well-Known Member
Licensed User
Hi,

I am trying to write a single txt file with the values from 2 map views.

Here is the code I have used:

B4X:
Dim map1 As Map
Dim map2 As Map
               
    map1.Initialize
    map2.Initialize
               
    map1.Put("Key1","Value1")
    map1.Put("Key2","Value2")
    map1.Put("Key3","Value3")

    map2.Put("K1","MyValue1")
    map2.Put("K2","MyValue2")
    map2.Put("K3","MyValue3")
               
    File.WriteMap(File.DirRootExternal , "MyMap.txt", map1)
The above works when writing map1 but can't work out how to also save map2 into the same txt file.

Anyone know how to save map1 and then add map2 at the end of the txt file ?
 

eurojam

Well-Known Member
Licensed User
Hey aaronk,
you can write two textfiles and merge them together with opening the files in append mode (last parameter of File.OpenOutput)...

Best regards
Stefan
 

aaronk

Well-Known Member
Licensed User
I ended up converting both maps into a List and then saving the List:

B4X:
    Dim map1 As Map
    Dim map2 As Map

    map1.Initialize
    map2.Initialize
 
    map1.Put("Key1","Value1")
    map1.Put("Key2","Value2")
    map1.Put("Key3","Value3")

    map2.Put("K1","MyValue1")
    map2.Put("K2","MyValue2")
    map2.Put("K3","MyValue3")

    Dim List1 As List
    List1.Initialize

    For i = 0 To Map1.Size - 1
        List1.Add(Map1.GetValueAt(i))
    Next
               
    For i = 0 To Map2.Size - 1
        List1.Add(Map2.GetValueAt(i))
    Next
   
    File.Writelist(File.DirRootExternal , "MyMap.txt", List1)
 
Top