Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

autoLink with onClick event

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

like image 709
Trương Vũ Ngọc Avatar asked Jul 05 '16 07:07

Trương Vũ Ngọc


3 Answers

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.

like image 170
JJ86 Avatar answered Nov 11 '22 10:11

JJ86


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.

like image 35
Rohan Avatar answered Nov 11 '22 09:11

Rohan


U can try Using :-

 Linkify.addLinks(txtView, Linkify.ALL);
like image 1
Aditi Avatar answered Nov 11 '22 09:11

Aditi