Android Question How to capture custom classes added in the activity?

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Sorry for my English.

I have a class: "myItem". This class returns a panel with several views. She has Some methods and properties.

I add this view variables times:

for x = 1 to y

dim m as myitem

m.initialize

activity.addview(m.asview, a, b, c, d)

Next

Okay so far.

Problem:

Some times I need to change properties of some views but there are no events.
So I can not use "sender".

Any idea?

Thank you.
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Store references to them in an Array or List (or even a Map, if you like) so that they can be retrieved later. Most Views will have a Tag property that you can set to help you identify them.
 
Upvote 0

Eme Fibonacci

Well-Known Member
Licensed User
Longtime User
Store references to them in an Array or List (or even a Map, if you like) so that they can be retrieved later. Most Views will have a Tag property that you can set to help you identify them.

I followed this idea.

I tried a list. Did not work. So I tried a map and it worked.

Dim map1 as Map :map1.Initialize
map1.Put (0, myitem)

and then:

dim c as myitem
c.Initialize

c=map1.Get(0)

and now I can change the properties. Very good!

One question. I'm adding the "own class" on a map does not it?
With many objects added to this map will be a great memory consumption?
Thanks a lot for the help.
 
Upvote 0

Roycefer

Well-Known Member
Licensed User
Longtime User
You're not putting a copy of an Object in your Map. You're putting a reference to your Object in the Map. It won't consume much more memory to have the reference stored in the Map. You just have to make sure that when you're done with an Object, you remove it from the Map so that the memory it is consuming can be released by the garbage collector.
 
Upvote 0

LucaMs

Expert
Licensed User
Longtime User
I would use a unique property for the class (for example Name) and I would use it as the key of the Map.

If the class is a custom view, I would use a Tag property (which can correspond to the panel tag)
 
Last edited:
Upvote 0
Top