Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <code>autoLink</code> attribute has an annoying bug: if you click in your example on the phone number, then return back and click on the second url link - it will open the phone number again. This attribute works so bad with multiple links, that I have implemented my own class, here is the link on Github <a href="https://github.com/vortexwolf/2ch-Browser/blob/79da45711dc2fb07a794ed0e0d47f619fb77ad09/src/com/vortexwolf/dvach/common/controls/ClickableLinksTextView.java">ClickableLinksTextView.java</a></p> <p>In your example you can replace your <code>TextView</code> class by my <code>ClickableLinksTextView</code> class in the xml-layout and change the code like this:</p> <pre><code>ClickableLinksTextView textView = (ClickableLinksTextView)view.findViewById(R.id.mytext); textView.setText("My text: +4412345678 Go to website: www.google.com Blah blah"); Linkify.addLinks(textView, Linkify.ALL); if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.HONEYCOMB) { textView.setMovementMethod(ArrowKeyMovementMethod.getInstance()); textView.setTextIsSelectable(true); // the autoLink attribute must be removed, if you hasn't set it then ok, otherwise call textView.setAutoLink(0); } </code></pre> <p>The original cause of the issue in your question is that the <code>LinkMovementMethod</code> class and the <code>textIsSelectable</code> attribute are not compatible at all, even Android OS developers admit this in <a href="http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/4.1.2_r1/android/widget/TextView.java#3494">the Android OS source code</a>.</p> <blockquote> <p><em>Do not change the movement method for text that support text selection as it would prevent an arbitrary cursor displacement.</em></p> </blockquote> <p>If the text view is selectable, the only 2 correct movement method values are <code>null</code> and <code>ArrowKeyMovementMethod</code>. That's why I set <code>ArrowKeyMovementMethod</code> explicitly in my example, because the <code>Linkify.addLinks</code> sets an incorrect movement method and I should revert it.</p> <p>As to the bug of the autoLink attribute, it is because android developers haven't copied link detection properly. You can look at the code example in the answer of @cheng yang, the code just takes the first link no matter how many of them you have.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload