Android Question (SOLVED) List in map I don't understand

yfleury

Active Member
Licensed User
Longtime User
Hi all.
I create a list with some data.
After that I create a map and I put the list in. I log the map and I see the list and it's data. Fine

I clear the list and log again the map and the list inside the map is empty.

I need to keep data list in map even if I delete the list

B4X: Copy
Sub Sub1
    list1.Add(1)
    list1.Add(2)
    list1.Add(3)
    list1.Add(4)

    map1.Put(1, list1)
    Log(map1) 'this show : (MyMap) {1=[1, 2, 3, 4]}
    list1.Clear
    Log(map1) 'this show : (MyMap) {1=[]}
End Sub
 
The output is correct. You put ONE list in a map. In the next step you clear the list. It's the same object.

I assume you want to add different lists. So put a "Dim List1 as List" before it each time and initialize it. This will create different lists.

It's like to put ONE box in a shelf with some things in it. If you empty it, it's empty. You need several boxes, not just one.
 
Upvote 0
You must add a new List each time.
Code: Copy
Sub Button1_Click
    counter=counter+1
    map1.Put(1, list)
    Log(map1)
    list1.Clear 'not needed
    Log(map1)
Sub1
End Sub

Sub Sub1
     Dim list1 As List 'these two lines will create a new list.
   list1.Initialize
    list1.Add(1)
    list1.Add(2)
    list1.Add(3)
    list1.Add(4)
End Sub
Well, I need to complete my small project to be explain more what I need. I will post it this night.... I go to work
 
Upvote 0
What is your expected output?
B4X: Copy
Copying updated assets files (1)
*** Service (starter) Create ***
** Service (starter) Start **
** Activity (main) Create, isFirst = true **
** Activity (main) Resume **
(MyMap) {1=[1, 2, 3, 4, 1]}
(MyMap) {1=[]}
(MyMap) {1=[1, 2, 3, 4, 2]}
(MyMap) {1=[]}
(MyMap) {1=[1, 2, 3, 4, 3]}
(MyMap) {1=[]}
(MyMap) {1=[1, 2, 3, 4]}
(MyMap) {1=[]}
 
Upvote 0
When I click GO I need to insert list in map and I can start a reset the list and add new items to list and by cliking GO add news items list to the map . This will appent few or more time.
 
Upvote 0
Back
Top