Android Question How to get view type inside panel ?

Discussion in 'Android Questions' started by adjie, Feb 12, 2015.

  1. adjie

    adjie Member Licensed User

    Below is my code :
    Code:
    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.
     
  2. mangojack

    mangojack Well-Known Member Licensed User

    Code:
    If v Is EditText Then
      Panel1.Removeview
     
    adjie likes this.
  3. adjie

    adjie Member Licensed User

    Thanks mangojack !
     
  4. mangojack

    mangojack Well-Known Member Licensed User

    I think this a better method ...
    Code:
    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
     
    DonManfred likes this.
  5. adjie

    adjie Member Licensed User

    what is the advantage of above code compare to the first code?
     
  6. mangojack

    mangojack Well-Known Member Licensed User

    adjie likes this.
  7. adjie

    adjie Member Licensed User

    Ohh.. I see !
    before trying above method, I also try the tag tricks. But ends with the same result like that gus.
    Thank you for the reference, I'll always remember it whenever doing any iteration.
     
  8. DonManfred

    DonManfred Expert Licensed User

    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
     
  9. adjie

    adjie Member Licensed User

    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:
    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: Feb 12, 2015
    mangojack likes this.
  10. klaus

    klaus Expert Licensed User

    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.
     
    lemonisdead, adjie and mangojack like this.
  11. adjie

    adjie Member Licensed User

    Thats make things more clear. Thanks Klaus !
     
  12. DonManfred

    DonManfred Expert Licensed User

    Remember: If you want to delete something then this solution you should avoid!
     
    adjie likes this.
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