Android Question how to browse a Map of Types?

Discussion in 'Android Questions' started by ThePuiu, Apr 15, 2019.

  1. ThePuiu

    ThePuiu Active Member Licensed User

    I have the following code:
    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.key = 
    jobs.Data = DateUtils.SetDate(
    jobs.ListaEchipe = mcal
    jobs.key = 
    jobs.Data = DateUtils.SetDate(
    jobs.ListaEchipe = mcal1
    Taskuri.Put(mcal, jobs.Data)
    Taskuri.Put(mcal1, jobs.Data)
    how can I get "Taskuri" Map values for a given "key" value?

    Thank you!
  2. Marcus Araujo

    Marcus Araujo Member Licensed User

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

    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 = 
    End If

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

    End if
    Erel likes this.
  3. Marcus Araujo

    Marcus Araujo Member Licensed 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.
  4. ThePuiu

    ThePuiu Active Member Licensed 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?

    Attached Files:

    Last edited: Apr 16, 2019
  5. Marcus Araujo

    Marcus Araujo Member Licensed 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).
  6. ThePuiu

    ThePuiu Active Member Licensed 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!
    Marcus Araujo likes this.
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice