iOS Question Remove View out of Bounds

Yvon Steinthal

Active Member
Licensed User
Longtime User
Hello,

I am currently having an error that i have trouble understanding...

I created 3 labels through a loop that read a map such as:

B4X:
For Each k As String In m1.keys
          
     Dim value As String = k
    
     Dim lbl As Label
     lbl.Initialize("Name_Tree")
     lbl.TextAlignment = lbl.ALIGNMENT_CENTER
     lbl.Text=value
     lbl.Tag ="Name_Tree"
     innerPnl.AddView(lbl,xpos,ypos,40*PARAMS.toDIP,40*PARAMS.toDIP)
     ypos = ypos+50
    
    
   Next

But i want to remove them from the view when another label is clicked, through such loop:

B4X:
Sub RemoveTreeView(value As String)
  
   For Each v As View In innerPnl
     If(v Is Label)Then
       Dim lbl As Label = v
       If(lbl.Tag=value)Then
      
         lbl.RemoveViewFromParent
        
       End If
     End If
   Next
  

End Sub

The error is on the removeviewfromparent, it says :"index 4 beyond bounds [0..2]"

I have removed view from panels before without a hiccup, but i am out of ideas right now...

Thanks

Y.
 

JanPRO

Well-Known Member
Licensed User
Longtime User
Hi,

there is a little mistake in your code:
B4X:
Sub RemoveTreeView(value As String)
 
   For Each v As View In innerPnl.GetAllViewsRecursive
     If(v Is Label)Then
       Dim lbl As Label = v
       If(lbl.Tag=value)Then
     
         lbl.RemoveViewFromParent
       
       End If
     End If
   Next
End Sub

This should work :)

Jan
 
Upvote 0
Top