Android Question How to get view type inside panel ?

adjie

Member
Licensed User
Longtime User
Below is my code :
Code: Copy
    For Each v As View In panel1.GetAllViewsRecursive
            v.RemoveView 'just need specific view (edittext) only to delete
        End If
    Next
So how to detect whether v is an EditText or not ?
Thanks.
 
Code: Copy
If v Is EditText Then
  Panel1.Removeview
 
Upvote 0
I think this a better method ...
Code: Copy
For i = Panel1.NumberOfViews - 1 To 0 Step -1
  Dim v As View = Panel1.GetView(i)
  If v Is EditText Then
    Panel1.Removeview
  End If
Next
 
Upvote 0
I'll always remember it whenever doing any iteration.
If you just want to iterate through all (without deleting) the first one is perfect. But if you want to remove objects in this loop then the second solutiion is better. Both solutions i could not show better. Thanx to @mangojack for this
 
Upvote 0
Agree with you @DonManfred , I thing it is about programming method. Why I notice this, because of my own foolish. And this happening two me for many year in vb6 :p. So, since got reference from @mangojack, I laugh and realize that first method will come to complicated zone for some object or function.
for example :
Code: Copy
For n = 0 to array.upperbound(1)
    if array(n,0) = 0 then
        array.deleterow n
    end if
Next
I always do that in many place, so.. instead of iterate from the top, it is nicer to do it from the bottom. With that, it doesn't need to detect what is the current position to iterate.
Once again, thanks all.
 
Last edited:
Upvote 0
There is one difference in the iteration principle between the two solutions:
With For i = Panel1.NumberOfViews - 1To0Step -1 you will get only the views on Panel1, if there is a child panel on Panel1 the views on this child panel will not be considered.

With For Each v As View In Panel1.GetAllViewsRecursive they will.
 
Upvote 0
There is one difference in the iteration principle between the two solutions:
With For i = Panel1.NumberOfViews - 1To0Step -1 you will get only the views on Panel1, if there is a child panel on Panel1 the views on this child panel will not be considered.

With For Each v As View In Panel1.GetAllViewsRecursive they will.
Thats make things more clear. Thanks Klaus !
 
Upvote 0
Back
Top