Open nAkhmedov opened 4 years ago
Does it work if you replace BetterLinkMovementMethod
with the framework LinkMovementMethod
?
Thank you for response. Nope, click and long click events are working when i set to TextView android:autolink="web" in xml(without above java codes).
Does it work if you replace BetterLinkMovementMethod with the framework LinkMovementMethod?
I meant:
textview.movementMethod = LinkMovementMethod.getInstance()
I understand you, no, it is not working with LinkMovementMethod class.
Whoops then it's unfortunately outside the control of BetterLinkMovementMethod
Do you have any suggestions on this issue?
Try overriding its touch listener?
So? How to handle clicks over a TextView outside links?
@nAkhmedov did u got any solution?
Here's a snippet of possible solution:
var wasLinkClicked = false
val detector = GestureDetectorCompat(context, object : GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapUp(e: MotionEvent): Boolean {
if (!wasLinkClicked) {
// handle click here
}
return true
}
})
val myMovementMethod = object : BetterLinkMovementMethod() {
override fun onTouchEvent(textView: TextView, text: Spannable, event: MotionEvent): Boolean {
val touchHandled = super.onTouchEvent(textView, text, event)
if (event.action == MotionEvent.ACTION_DOWN) {
wasLinkClicked = touchHandled
}
detector.onTouchEvent(event)
return true
}
}
textView.movementMethod = myMovementMethod
When i use this lib in adapter, onClick/onLongClick events are working for only links. If i type simple text and tring to click or long click no action, even parent view does not handle these actions.