In Android:
Given a View from an onTouchEvent, how can I remove the View and its parent?
I have a LinearLayout in which I have a View. Clicking on the View creates a sub-layout inside of the LinearLayout. That sub-layout needs its own onTouchListeners so I cannot attach an onTouchListener to the parent LinearLayout because that will always block onTouchListeners to my sub-layout.
Therefore, I need a means to remove the parent layout given its child layout. I can already remove child layouts from their parents.
If you know how to remove child views from a parent, stick with what you know ;) The idea is to elevate to a position in the view tree where you can remove your parent view as a child. How do you do that? Easy, get the grandparent view of your view and remove your parent view from the grandparent.
((ViewGroup)view.getParent().getParent()).removeView((ViewGroup)view.getParent());
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With