Android Question how to browse a Map of Types?

ThePuiu

Active Member
Licensed User
Longtime User
I have the following code:
B4X:
Type ZiLucru(key as Int, Data As Long, ListaEchipe As Map)
Dim Taskuri As Map

....................

Dim mcal As Map = CreateMap("POPESCU":1,"IONESCU":2)
Dim mcal1 As Map = CreateMap("MARINESCU":3,"PANTEA":3)

Dim jobs As ZiLucru
jobs.Initialize
jobs.key = 1
jobs.Data = DateUtils.SetDate(2019,4,1)
jobs.ListaEchipe.Initialize
jobs.ListaEchipe = mcal
    
jobs.Initialize
jobs.key = 2
jobs.Data = DateUtils.SetDate(2019,4,2)
jobs.ListaEchipe.Initialize
jobs.ListaEchipe = mcal1
    
Taskuri.Initialize
Taskuri.Put(mcal, jobs.Data)
Taskuri.Put(mcal1, jobs.Data)

how can I get "Taskuri" Map values for a given "key" value?

Thank you!
 

Marcus Araujo

Member
Licensed User
Longtime User
If I got it right, you could to go through all the values and stop when the key is found.

B4X:
Dim keyFound as Boolean = False
For Each mapKey As Map In m
    Dim value As ZiLucru = m.Get(mapKey)
    If value.key = the_key_you_are_looking_for Then 
        ' Do something if the key is found

        keyFound = True
        Exit
    End If
Next

If keyFound = False Then
    ' Do something if the key is not found

End if
 
Upvote 0

Marcus Araujo

Member
Licensed User
Longtime User
Ah, and I noticed that you are re-initializing "jobs" (for the second time) before adding it to Taskuri.
So, at the end, you are adding two times the second "jobs", which makes the first one useless.
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
the two inserts lead to the insertion of both objects into the Taskuri structure ... see the picture


Or is there a simpler method of navigating through a structure similar to the one in the image?
 

Attachments

  • result.png
    4.7 KB · Views: 140
Last edited:
Upvote 0

Marcus Araujo

Member
Licensed User
Longtime User
It does lead the insertion of both items but only their keys (mcal and mcal1). Their values are the same (jobs.Data) but should be different dates, right?

I am afraid there's no simpler method for navigating the structure the way you proposed, but there may be simpler ways to code what you want to do (I don't know what your goal is, but I have a hunch that Lists might help).
 
Upvote 0

ThePuiu

Active Member
Licensed User
Longtime User
yes, you are right about jobs.Data.

I couldn't stand for help anymore and I changed the concept ... now I'm using json and everything works perfectly.
thank you for your involvement!
 
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…