Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ListView onItemLongClickListener does not prevent link taps

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.

like image 541
mikejonesguy Avatar asked Jul 31 '12 15:07

mikejonesguy


1 Answers

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.

like image 181
mikejonesguy Avatar answered Oct 01 '22 08:10

mikejonesguy