Autolink action tracking on texview onClickListner

I have a listview, each element is a textView with the autoLink = "web | email" .Link property will work correctly, but I want to start another action when the text is clicked, other than the web email that was not there. So I used setOnClickListner for textView, which also worked smoothly. My problem is that when I click on the email link or web link, both actions will be performed and other actions will open. How to prevent this?

+4
source share
2 answers

I have a solution.
I used the getSelectionStart() and getSelectionEnd() functions of the getSelectionStart() class,

  textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if(textView.getSelectionStart()==-1&&textView.getSelectionEnd()==-1){ //This condition will satisfy only when it is not an autolinked text //onClick action } } }); 
+3
source

Try it:

in layout :: android:autoLink="web"

OR

  TextView t2 = (TextView) findViewById(R.id.text2); t2.setMovementMethod(LinkMovementMethod.getInstance()); 
0
source

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


All Articles