Android Question Array of panels??

ilan

Expert
Licensed User
Longtime 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

B4X:
Sub Globals
    Type blocks(pnl As Panel, left As Int, right As Int, top As Int,bottom As Int,action As String)
Dim bl(100) As 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!!
 

DonManfred

Expert
Licensed User
Longtime User
i would write it like this i think...

B4X:
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
 
Upvote 0

ilan

Expert
Licensed User
Longtime 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... :(
 
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
but i dont understand why it did not worked before
with the recursive method you dont get a instance of the object. In
B4X:
For Each v As View
v is not an reference to an panel instance

B4X:
 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)
 
Upvote 0
Top