Android Question Array of panels??

Discussion in 'Android Questions' started by ilan, Jun 6, 2015.

  1. ilan

    ilan Expert Licensed User

    i want to add all panels inside a panel and do something with them the problem if i call the panel i get allways the last added panel to the array and not the right panel

    i do it like this

    Code:
    Sub Globals
        
    Type blocks(pnl As Panel, left As Int, right As Int, top As Int,bottom As Int,action As String)
    Dim bl(100As blocks 'max panels
    End Sub

    '....

    Sub addpanelstoarray
        
    Dim i As Int = 0
        blsize = 
    0
      
        
    For Each p As Panel In pnl1.GetAllViewsRecursive
            bl(i).pnl = p
            bl(i).left = p.Left
            bl(i).right = p.Left + p.Width
            bl(i).top = p.Top
            bl(i).bottom = p.Top + p.Height
            bl(i).action = p.Tag
            i = i+
    1
        
    Next

        blsize = i
    End Sub

    sub btn1_click
    bl(
    0).pnl.SetVisibleAnimated(400,False)
    end sub
    the location of every panel is correct only if i want to change the panel visible to false it change always the last panel in the array and not the panel i choose but all other data is correct!!
     
  2. DonManfred

    DonManfred Expert Licensed User

    i would write it like this i think...

    Code:
    Sub addpanelstoarray
        
    Dim i As Int = 0
        blsize = 
    0
     
        
    For Each v As Panel In pnl1.GetAllViewsRecursive
            
    if v is Panel then
                
    dim p as panel = v
                bl(i).pnl = p
                bl(i).left = p.Left
                bl(i).right = p.Left + p.Width
                bl(i).top = p.Top
                bl(i).bottom = p.Top + p.Height
                bl(i).action = p.Tag
                i = i+
    1
            
    end if
        
    Next

        blsize = i
    End Sub
     
    ilan likes this.
  3. ilan

    ilan Expert Licensed User

    thanx DonManfred it worked i only changed:
    For Each v As View ... (not as panel)

    but i dont understand why it did not worked before... :(
     
  4. DonManfred

    DonManfred Expert Licensed User

    with the recursive method you dont get a instance of the object. In
    Code:
    For Each v As View
    v is not an reference to an panel instance

    Code:
    if v is Panel then
            
    dim p as panel = v
    get v and initiate an referenced instance of v as p (a panel). p now can be used to fill a list/whatever....

    Inform about object references (erel has posted something about)
     
    eurojam and ilan like this.
  5. ilan

    ilan Expert Licensed User

    ok thanx now i got it :)
     
Loading...
  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