android - Disable click event on linear layout childs - android

I have a LinearLayout that acts like a container for views.
I'm inflating a different layout programatically and adding an OnClickListener and adding it in my LinearLayout.
What I want to achieve is to have the option to disable those OnClickListener on those views that I've inflated and added to my LinearLayout.
Can I just disable the OnClickListener on the parent LinearLayout to disable as well all the other child's OnClickListener?
Setting the parent LinearLayout click listener to null doesn't work though, any ideas?
THanks.

You can put the onClickListener as null to the views for which you don't want to add the listener instead of setting the listener as null to the parent layout.

Related

Click Animation parent/child

I have on LinearLayout (I'll call it the parent) with inside an other LinearLayout (the child)
When I listen to a click on the child layout, I'd like to make the clickable animation on the parent and not only on the child.
How can I make that?
Thank you
One way to do it is to add a OnClickListener to the parent layout and then add the attribute android:duplicateParentState="true" to the inner layout. That way, when you press/click on the inner layout, the parent layout will also receive the event and process any animations and if it was being actioned directly.

How can I add again a programmatically created linearlayout to another linearlayout

I have a child linearlayout created programmatically and added on a parent linearlayour programmatically.
parentlayout.addView(childlayout)
But, the I want to add again the child layout to another linearlayout, it returns an error, is it possible? What is the best way to do that?
Create another instance of the same class, and set the same properties. I mean Inflate your View again if needed. Because A single View cannot be a child of two ViewGroup parents.
Each view can have only one parent possible.
So you can not add same child to another linear layout.
What you can do is make another instance, apply same properties which you given to previous child. and then add this instance to the parent view.

Suppress Child View OnClickListeners

I have a linear layout that has several views within it. These views may have click listeners already associated with them when they are added to the layout. I want to disable all click listeners for children of this linear layout and have only one listener at the top level.
As a variant you may go through all child views and make them not clickable.
you can do that through the xml by adding the options focusable and clickable with false as values to the child views and with true values to the parent.
Another option would be using the same OnClickListener for parent and child views.

Android: Let Parent View Handle On Click

I have a RelativeLayout that contains a few items: An ImageView and a few small TextView's.
Functionally I want to have the same on click event fire when anything in the RelativeLayout is clicked.
Visually I want to see the background of the RelativeLayout change so that it shows the entire layout (or "item") is being clicked.
My problem is that every time I click on the TextView's the on click doesn't propagate back to the parent view and so the background color doesn't change. How can I do this?
Ensuring you got no OnClickListener assigned to any of the childs of your RelativeLayout shall usually suffice for them to not receive clicks. Also check if you got no android:clickable="true" set by any chance for it. Then once you assing OnClickListener to your RelativeLayout it should get all the clicks.
for some items that has internal OnClickListener and you cannot easily remove their implementation of OnClickListener like SwitchComat, you can set
android:descendantFocusability="blocksDescendants"
on your parent layout. by adding this attribute to the parent view, non of the children will receive click events regardless of having onClickListener or not.
more on descendantFocusability

Android, Layout clicklistener and subview click through problem

I have a RelativeLayout to which I add buttons and set their onCLickListener to the current Activity where I handle their clicks.
Under a particular circumstance I need to set the RelativeLayout onClickListener also, but then once finished with the required clicking on the layout, I need to allow clicking on the buttons again. (i.e. clicking throug hthe layout)
If I set the layout's click listener to null I can no longer click either the layout or the buttons that are it's child views.
What am I doing wrong?
EDIT: I seem to have fixed it by setting;
relativeLayout.setClickable(false);
Have you tried:
relativeLayout.setOnClickListener(null);
relativeLayout.setDescendantFocusability(ViewGroup.FOCUS_AFTER_DESCENDANTS);
?

Categories

Resources