Search code examples
androidandroid-layoutonclickandroid-relativelayout

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?


Solution

  • 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.