Android Question How can I work with maps values?

Hello everyone, firstly I have to tell you that I'm a beginner so please, be patient.

Here is my problem, in my code, I have a map and I need to a sum with these values. Here is my code

B4X:
ListaArticulos.Initialize   
    NewArt.Initialize
    NewArt.Put("nombre","Harina COLOLO 0000 1kg.")
    NewArt.Put("marca","COLOLO")
    NewArt.Put("comercio","'El Campo'")
    NewArt.Put("precio", 50)
    NewArt.Put("precio antes", 60)
    NewArt.Put("categoria","Almacén")
    NewArt.Put("unidad", 1)
    
    
Sub btn_mas_unidad_Click

        NewArt.Get("unidad") = NewArt.Get("unidad") + NewArt.Get("unidad")
    
End Sub


I need that when user click btn_mas_unidad the map "unidad" change and show in a label "2". And if the user, for instance click five times the btn, the label show "5", how can I do that?
 

cklester

Well-Known Member
Licensed User
You should be adding one, since you want to click five times and show "5."

B4X:
dim val as int = NewArt.Get("unidad")
val = val + 1
NewArt.Put("unidad",val)

Or, in one line:

B4X:
NewArt.Put("unidad",NewArt.Get("unidad")+1)
 
Upvote 0
Top