Android Question (solved)How to code Map Collection instead of the old code?

Theera

Well-Known Member
Licensed User
Longtime User
refer to: https://www.b4x.com/android/forum/threads/map-collection-the-most-useful-collection.60304/#content

Now I have the old code
B4X:
    CLV1.Add(CreateItem(CLV1.AsView.Width,"Low Price",1000),"")
    CLV1.Add(CreateItem(CLV1.AsView.Width,"Medium Price",10000),"")
    CLV1.Add(CreateItem(CLV1.AsView.Width,"High Price",10000000),"")

I would like to use Map collection,but there is my mistake which I don't understand it.
B4X:
    Dim Products  As Map =CreateMap("Low Price":1000,"Medium Price":10000,"High Price":10000000)
    For Each Products As String In Products.Keys
        Dim Price As Float=Products.Get(Products)
        CLV1.Add(CreateItem(CLV1.AsView.Width,${Products},{Price}),"")      '<==This line is my problem
    Next
 
Last edited:
Solution
There is another error, try this:

B4X:
Dim Products  As Map = CreateMap("Low Price":1000,"Medium Price":10000,"High Price":10000000)
For Each Product As String In Products.Keys
    Dim Price As Float = Products.Get(Product)
    CLV1.Add(CreateItem(CLV1.AsView.Width, Product, Price),"")
Next

For Each Product, not Products !!

Theera

Well-Known Member
Licensed User
Longtime User
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User
There is another error, try this:

B4X:
Dim Products  As Map = CreateMap("Low Price":1000,"Medium Price":10000,"High Price":10000000)
For Each Product As String In Products.Keys
    Dim Price As Float = Products.Get(Product)
    CLV1.Add(CreateItem(CLV1.AsView.Width, Product, Price),"")
Next

For Each Product, not Products !!
 
Last edited:
Upvote 0
Solution

Theera

Well-Known Member
Licensed User
Longtime User
There is another error, try this:

B4X:
Dim Products  As Map = CreateMap("Low Price":1000,"Medium Price":10000,"High Price":10000000)
For Each Product As String In Products.Keys
    Dim Price As Float = Products.Get(Product)
    CLV1.Add(CreateItem(CLV1.AsView.Width, Product, Price),"")
Next

For Each Product, not Products !!
Many thanks for kind of you.
 
Upvote 0

sirjo66

Well-Known Member
Licensed User
Longtime User

Attachments

  • Immagine.png
    Immagine.png
    1.8 KB · Views: 36
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I don't think you should force a member to make your post a 'Solution' He already gave you many likes. It is up to them to give the reaction they want to give. Some members get a lot of help and never make any reactions. Some others are more appreciative. Look and see in the forum how many times many of us give a very fitting answer that deserves a reaction, but the answer doen't even get rewarded.
 
Upvote 0

Theera

Well-Known Member
Licensed User
Longtime User
I don't think you should force a member to make your post a 'Solution' He already gave you many likes. It is up to them to give the reaction they want to give. Some members get a lot of help and never make any reactions. Some others are more appreciative. Look and see in the forum how many times many of us give a very fitting answer that deserves a reaction, but the answer doen't even get rewarded.
I'm not seriously about his advice.He helps me learn how to do. Thank you for caring my felt,Mahares. I would like to tell everyone ,if someone need me to do anything,I have ready to learn all. Thank you all of replies.
 
Upvote 0
Top