I´ve made a simplified version of a problem I struggled with for hours. I´m pretty sure that in an earlier version of b4a, this worked fine.
The expected result is that the only item in the list remains the same, since only once in the code is a value being added to it. However, when the content of the map that is previously added to the list, the item in the list is also changing.
I tried with an Int instead of a map, and here the value remains the same = succesful.
I could just do m.initialize before the new value is replacing the old one in the map, but in the app I´m working on, there are multiple values in the map which I don´t want to be reset.
I then tried creating another map to which the change is made, that copies the first map (m2=m) but still the list seems to have a need to stay in sync with the map change.
My solution was to create a new map, and then manually copy each element of the first map to it, m2.put("1",m.get("1") etc. which seems pretty clumsy to me.
But perhaps there´s a good explanation to this, and something I can learn from.
Thanks in advance!
B4X:
Dim l As List
Dim m As Map
l.Initialize
m.Initialize
m.Put ("1",2)
l.Add (m)
Log (l)
m.Put ("1",1)
Log (l)
The expected result is that the only item in the list remains the same, since only once in the code is a value being added to it. However, when the content of the map that is previously added to the list, the item in the list is also changing.
B4X:
(ArrayList) [{1=2}]
(ArrayList) [{1=1}]
I tried with an Int instead of a map, and here the value remains the same = succesful.
I could just do m.initialize before the new value is replacing the old one in the map, but in the app I´m working on, there are multiple values in the map which I don´t want to be reset.
I then tried creating another map to which the change is made, that copies the first map (m2=m) but still the list seems to have a need to stay in sync with the map change.
My solution was to create a new map, and then manually copy each element of the first map to it, m2.put("1",m.get("1") etc. which seems pretty clumsy to me.
But perhaps there´s a good explanation to this, and something I can learn from.
Thanks in advance!