6

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?

Sababado
  • 2,524
  • 5
  • 33
  • 51

2 Answers2

9

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.

Marcin Orlowski
  • 72,056
  • 11
  • 123
  • 141
  • Thank you for the quick response. I had set a click event to see what items were getting clicked and it turns out that was forcing the text view to receive the click event (ignoring clickable="false"). – Sababado Nov 19 '12 at 20:51
  • 1
    thanks a lot brother, this was really bugging me. its very easy to neglect the presence of `android:clickable="true"`. removing this solved my problem. – Akash Raghav Sep 22 '16 at 13:32
0

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