Android Question Cannot store views in array in GetAllViewsRecursive loop

Discussion in 'Android Questions' started by Thomas., Apr 5, 2015.

  1. Thomas.

    Thomas. New Member Licensed User

    Hi all,

    1st I'd like to say thank you for this very informative forum! I've read a lot here and found many solutions. But I could'nt find one for this problem. Maybe someone has an idea (hopefully).

    I have 5 ImageViews inside a Panel which I originally copied from the UserInteraceButtonToolbox sample. To get later access to each one of these ImageViews I thought I could copy them to an array while I initialized them:
    Dim btnPage(6As ImageView
    Dim i As Int
    Dim h, w, b As Int

    pnlToolbox.Width = 
    w = pnlToolbox.Width / 
    pnlToolbox.Height = w
    h = w * 
    b = (w - h) / 

    For Each v As ImageView In pnlToolbox.GetAllViewsRecursive
        v.Height = h
        v.Width = h
        v.Top = b
        v.Left = w * (v.Tag - 
    1) + b
        btnPage(v.Tag) = v        
    ' store reference to ImageView in array
        Log("T: " & btnPage(v.Tag).Tag)

    For i = 1 To 5
    Log("t: " & btnPage(i).tag)
    While executing this code I get this in the debugging window:
    To me this looks as if the array contains all 5 ImageViews. But, while executing this in the same sub
    For i = 1 To 5
    Log("t: " & btnPage(i).tag)
    I get
    And after this all 5 references in the array point to the last inserted ImageView.

    What am I doing wrong?

    Attached Files:

    Last edited: Apr 5, 2015
  2. DonManfred

    DonManfred Expert Licensed User

    For Each v As ImageView
    will not work. You can not limit the result from GetAllViewRecursive

    Try this
    For Each v As View In pnlToolbox.GetAllViewsRecursive
    if v is Imageview then
    dim iv as imageview = v
    end if
  3. Thomas.

    Thomas. New Member Licensed User

    Thank you DonManfred for this quick answer. It works!

    What I thought is, that if there are only ImageViews on the panel it should work my way.

    Have a nice Easter! And thanks again!
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice