Android Question get map item index by ID

leitor79

Active Member
Licensed User
Hi,

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.

Regards!
 

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.

B4X:
        j=myMap.Size-1
        For i=j To 0 Step -1
            m=myMap.GetValueAt(i)
            If M.id=targetM.ID Then
                Exit
            End If
        Next
           
        tmpPanel=lstItems.GetPanel(i)
        tmpLabel=tmpPanel.GetView(0)
by the way; I could match the tmpLabel.Tag to m.id 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!
 

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:
B4X:
    Type MapElement (ID As Long, myLabel As Label...)     
    Dim m As MapElement
    ...
    m=myMap.Get(mykey)
    tmpLabel = m.myLabel
 

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.

Regards!
 
Top