I need a little help. How I can check is a view belongs to a linearlayout or not?
I have an ImageButton and i need a condition that verify if belongs to a linearlayout or not.
Haven't tried this, but it should work. Assuming that your ImageButton is always a direct child of your LinearLayout.
View parent = (View)mContent.getParent();
if (parent instanceof LinearLayout) {
// do stuff
}
You can use the findViewById method on the LinearLayout. From the JavaDoc "Look for a child view with the given id. If this view has the given id, return this view."
LinearLayout layoutWithButton = (LinearLayout)findViewById(R.id.layout_with_button);
ImageButton buttonInLayout = (ImageButton)layoutWithButton.findViewById(R.id.button_in_layout);
if (buttonInLayout != null) {
// Found
}
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