= String REG = "\ d +" TextClickableSpan. text =
===
When I want to perform processing in onClick (), I find that I cannot get the position of my current click. This reminds me of a method called onTouchEvent, unfortunately, this method is not available in ClickSpan. So I customized a TouchableSpan class.
TouchableSpan CharacterStyle
There are two methods. The first method is copied directly from ClickableSpan. Obviously, it is used to set the style, including color and underline. The second method is onActionUp (View view, MotionEvent event). This is a custom event used to respond to events when we click the loose. Here, I input a MotionEvent, in this way, we can get the coordinates of the click. However, another problem occurs. In LinkMovementMethod, only the onClick () method of ClickableSpan is called. So I finally wrote a TouchableMovementMethod to inherit the LinkMovementMethod class.
TouchableMovementMethod (sInstance == = action = (action == MotionEvent.ACTION_UP ||== x = ( y = (-=-=+=+== line = off == buffer.getSpans(off, off, ClickableSpan.);
if (link.length != 0) { if (action == MotionEvent.ACTION_UP) { link[0].onClick(widget); } else if (action == MotionEvent.ACTION_DOWN) { Selection.setSelection(buffer, buffer.getSpanStart(link[0]), buffer.getSpanEnd(link[0])); } return true; } else { Selection.removeSelection(buffer); } } return false; }}
The code is very simple. I just rewritten the onTouchEvent method (this method is originally available in LinkMovementMethod). I made some modifications so that it can support the original ClickableSpan, it also supports TouchableSpan. In this way, the problem of obtaining click coordinates is very good ,,
Related blog posts: Customize the clickable ImageSpan and built-in "View" in TextView
Parses URLs in TextView and other specified special strings and click events