Environment:
I have an Android ListView
with rows that consist of TextViews containing some HTML with tappable links (URLSpans
). On the ListView, I have set an OnItemLongClickListener
to listen for long click events on individual rows.
Goal: When I receive a long click event, I want to DISABLE taps on the links for the same touch event, but I'm not seeing how to do this. The long click fires correctly, but then as soon as I lift my finger, the link tap also fires.
What I've Tried Already:
I've tried returning true (and false) on the onItemLongClick
method -- it doesn't seem to make a difference either way. I've tried to intercept the MotionEvent.ACTION_UP
after a long click so that I can temporarily consume the link tap, but the ACTION_UP
doesn't fire -- at least not on the ListView
.
I did some more searching and found this answer to a similar question: Android TextView Linkify intercepts with parent View gestures
I used the concepts from this answer to solve my problem. I extended the TextView
class and overrode onTouchEvent
and look to see if I'm tapping on a link on touch down events. If I am, I save that link and "click" it programmatically on my ListView.onItemClick
if I didn't encounter an LongClick
first. Yuck.
If anybody else has a more elegant way to solve the problem, post it and I'll accept your answer if it works. If not, I'll accept my own answer in a few days.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With