Android Question get map item index by ID

Discussion in 'Android Questions' started by leitor79, Apr 26, 2015.

  1. leitor79

    leitor79 Active Member Licensed User


    I have a map storing listview items. I need to update a panel item by GetPanel(index) function, and I'm wondering if there is a better way to get the item index than using a for loop.

  2. Erel

    Erel Administrator Staff Member Licensed User

    Not sure that I understand. Are you using ListView or CustomListView? Can you post the code that looks for the correct index?
  3. leitor79

    leitor79 Active Member Licensed User

    Hi Erel, thanks for your answer. I've read my question and sure, it's not clear, sorry for that.

    I have a customlistview indeed, and a Map to store info I use to load the customlistview. When I update a map item I want to edit a label inside one of the customlistview's panels, the one corresponding to the map's item.

    My code is something like this:

    m is some object, targetM is another object same type.

    For i=j To 0 Step -1
    If Then
    End If
    by the way; I could match the tmpLabel.Tag to in order to easily (and safer) way to get the label by some ID? If I add some other stuff into the panel, besides the label, maybe getview(0) won't work anymore...

    Thank you very much!
  4. Erel

    Erel Administrator Staff Member Licensed User

    Going over all items of a map is not the best solution.

    You should instead create another map that maps between the ids and the index. Then you will be able to easily get the index.
    thedesolatesoul likes this.
  5. eurojam

    eurojam Well-Known Member Licensed User

    an other solution: add the label to your custom type and hold it the same map. Then you have direct access to the label, something like this:
    Type MapElement (ID As Long, myLabel As Label...)     
    Dim m As MapElement
        tmpLabel = m.myLabel
  6. leitor79

    leitor79 Active Member Licensed User

    Thanks Erel and Eurojam! I like Eurojam solution, I found it very elegant, I'll try to implement that and If I can't I will use Erel's advice.

  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