ListView onItemLongClickListener does not prevent link hooks

Environment: I have an Android ListView with strings consisting of TextViews containing some HTML with tappable links ( URLSpans ). In ListView, I set OnItemLongClickListener to listen for long clicks on individual rows.

Purpose: When I receive an event with a long click, I want to DISABLE the link taps for the same touch event, but I don’t see how to do it. A long click fires correctly, but then as soon as I lift my finger, the link arrow also fires.

What I already tried: I tried to return true (and false) using the onItemLongClick method - it seems to have nothing to do with it anyway. I tried to intercept MotionEvent.ACTION_UP after a long click so that I could temporarily use the link, but ACTION_UP does not work - at least not on the ListView .

+6
source share
1 answer

I did a few more searches and found this answer to a similar question: Android TextView Linkify intercepts with parent gesture View

I used the concepts from this answer to solve my problem. I extended the TextView class and overridden onTouchEvent and looked to see if I click on the link when I click on events. If so, I save this link and "click" programmatically on my ListView.onItemClick , if I did not encounter LongClick first. Ugh.

If anyone else has a more elegant way to solve the problem, post it and I will accept your answer if it works. If not, I will accept my answer in a few days.

+1
source

Source: https://habr.com/ru/post/921776/


All Articles