5

I have a list of web address display in a ListView. Each item of ListView have a TextView and an ImageView. TextView have attribute autolink="web".

I also have event: onItemLongClick in this ListView to open details of each others. But when I do long click event on each item in list, they do open new page also open browser with link website in TextView.

How can I set when onItemLongClick, the TextView can't click into link? I try set TextView.setLinkClickable(false) but it isn't working.

Many thanks

AskNilesh
  • 67,701
  • 16
  • 123
  • 163

3 Answers3

2

You can achieve what you want in this way.

  1. on your .xml, add this to the TextView :

    TextView ... android:autoLink="web" android:textIsSelectable="true"

  2. on your code use ListView click behavior and longClick behavior.

JJ86
  • 5,055
  • 2
  • 35
  • 64
1

U can try Using :-

 Linkify.addLinks(txtView, Linkify.ALL);
AskNilesh
  • 67,701
  • 16
  • 123
  • 163
Aditi
  • 455
  • 4
  • 13
0

In your onItemLongClick() method, return true to indicate that you have consumed the click event and it should not be passed on to any other listeners.

According to the docs, the return value is described as -

boolean true if the callback consumed the long click, false otherwise

Returning true will NOT pass the long click event, which is also a click event, to the OnItemClickListener.

Rohan
  • 1,180
  • 2
  • 15
  • 28
  • That's how it should work, but unfortunately it doesn't in practice. The xml attribute runs independently of whether the longClick returns true. – Michael Plischke Apr 30 '23 at 23:10