How to pass a view's onClick event to its parent on Android?

shiami picture shiami · Dec 11, 2010 · Viewed 106.9k times · Source

I have a TextView in a layout whos background is a Selector. And the TextView's text is set to Spanned from HTML. Then I set the TextView with the LinkMovementMethod.

Now when I tap on the TextView, the click event is not sent to its parent layout to trigger the selector.

How should this be solved?

Answer

siyb picture siyb · Sep 23, 2013

Declare your TextView not clickable / focusable by using android:clickable="false" and android:focusable="false" or v.setClickable(false) and v.setFocusable(false). The click events should be dispatched to the TextView's parent now.

Note:

In order to achieve this, you have to add click to its direct parent. or set android:clickable="false" and android:focusable="false" to its direct parent to pass listener to further parent.