Failed to set textView1.setAutoLinkMask (0) - it remains clickable

I am trying to reuse TextView. Sometimes it contains a url, and sometimes not. If I try to return a TextView to textView.setAutoLinkMask (0), unfortunately there is nothing, and the new text will remain available.

TextView snippet = new TextView(); snippet.setText("someText"); if (ifSomeTextContainsURL) { // Recognize web URLs Linkify.addLinks(snippet, Linkify.WEB_URLS); snippet.setLinksClickable(true); } else { Linkify.addLinks(snippet, 0); snippet.setLinksClickable(false); snippet.setAutoLinkMask(0x00000000); } 

I tried the above code, but it does not work for me. thanks for reference

+4
source share
2 answers

I decided to solve this problem by installing autolinkmask before I installed the TextView text:

 textview.setAutoLinkMask(Linkify.ALL); textview.setText("String with url - http://www.example.com/"); 
+15
source

You have already found the answer, but to clarify it again ...

The documentation for the setAutoLinkMask(int) method is here

says that: "Sets the autolink mask for text. See Linkify.ALL and peers for possible values."

therefore, only the values ​​listed in the docs for Linkify here are estimated. '0' is not one of them, so it makes no sense to send it to this method.

+1
source

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


All Articles