AutoLink with onClick event

I have a list of displaying web addresses in a ListView . Each ListView item has a TextView and ImageView . TextView have the autolink="web" attribute.

I also have an event: onItemLongClick in this ListView to open each other's details. But when I make a long click on each item in the list, they open a new page and open a browser with a link website in TextView .

How can I set when onItemLongClick , TextView cannot click the link? I am trying to set TextView.setLinkClickable(false) , but it does not work.

Thank you very much

+5
source share
3 answers

You can achieve what you want in this way.

  • in your .xml, add it to the TextView :

    TextView ... Android: AutoLink = "web" android: textIsSelectable = "true"

  • in your code use ListView click behavior and LongClick behavior.

+1
source

U can try: -

  Linkify.addLinks(txtView, Linkify.ALL); 
+1
source

In your onItemLongClick() method, return true to indicate that you used the click event and cannot be passed to other listeners.

According to the docs, the return value is described as

boolean true if the callback consumes a long click, false otherwise

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

+1
source

All Articles