Does a parent click make all child elements interactive?

There is a LinearLayout with lots of children. When a user touches any of these children, the same method will be called. In order not to implement the same onClickListener for each element, I implemented onClickListener for the parent LinearLayout ONLY .

Now, when I click anywhere in the frame of the parent layout, the desired method is called just like I implemented a listener for all the children.

Q: Can I assume that whenever I implement onClickListener for a parent, all its children will respond to the click event?

Q: What happens if any child has its own onClickListener ? Will there be a collision or click on this element, will there be only its own click event?

+16
android onclick android-linearlayout clickable
Nov 15 '11 at 10:40
source share
1 answer

You answered your first question with your second question. ClickEvent will be delivered to the youngest child in the layout hierarchy. If this element does not have onClick behavior, it passes the event to its parent until the event is processed.

Therefore, you can consider LinearLayout as one unit for your onClick behavior. If you create another element that can be clicked inside the layout, make it large enough to reduce the likelihood that the user will lose the correct element.

+27
Nov 15 '11 at 10:45
source share



All Articles