Accessing dynamically created view

sorex

Expert
Licensed User
Longtime User
Hello,

I'm creating a few labels on the fly and want to access their properties later on.

Unfortunately I can't seem to get it working.

here's the loop...

B4X:
For x=0 To 10-1
Dim mypic As mypic.Initialize("")
mypic.Tag=x
Activity.AddView(mypic, 0, x*s, Activity.Width , 5)
Next

it seems that I can access the last created object with

mypic.width=1

is there a way to acces it via the tag like mypic(3) in some way?
 

klaus

Expert
Licensed User
Longtime User
This looks strange to me ?
B4X:
Dim mypic As mypic.Initialize("")
You could use either :
- an array of labels
B4X:
Dim mypic(10) As Label
.
.
For x=0 To 9
    mypic(x).Initialize("")
    mypic(x).Tag=x
    Activity.AddView(mypic(x), 0, x*s, Activity.Width , 5)
Next
.
.
mypic(i).Width = 1
- or with this (works as is only if you have no other views in the activity)
B4X:
Dim lbl As Label
lbl = Activity.GetView(i)
lbl.Width = 1
Best regards.
 
Upvote 0

sorex

Expert
Licensed User
Longtime User
yeah, something got messed up with the copy paste.

your array thing works excellent, thanks!
 
Upvote 0
Top