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?
If your
TextView
create click issues, than removeandroid:inputType=""
from your xml file.This answer is similar to Alexander Ukhov's answer, except that it uses touch events rather than click events. Those event allow the parent to display the proper pressed states (e.g., ripple effect). This answer is also in Kotlin instead of Java.
Put
in child then the views get its drawable state (focused, pressed, etc.) from its direct parent rather than from itself. you can set onclick for parent and it call on child clicked
Sometime only this helps:
Another variant, works not always:
Declare your
TextView
not clickable / focusable by usingandroid:clickable="false"
andandroid:focusable="false"
orv.setClickable(false)
andv.setFocusable(false)
. The click events should be dispatched to theTextView
's parent now.Note:
In order to achieve this, you have to add click to its direct
parent
. or setandroid:clickable="false"
andandroid:focusable="false"
to its direct parent to pass listener to further parent.If you want to both
OnTouch
andOnClick
listener to parent and child view both, please use below trick:User ScrollView as a Parent view and inside that placed your child view inside Relative/LinearLayout.
Make Parent ScrollView
android:fillViewport="true"
so View not be scrolled.Then set
OnTouch
listener to parent andOnClick
listener to Child views. And enjoy both listener callbacks.