I have created a onTouchListener
. Unfortunately onTouch() method throws
me a warning:
com/calculator/activitys/Calculat
I had a similar issue with a MultiTouchListener
and solved it implementing a GestureDetector
and listening for a SingleTap
(This does not remove the warning but starts to triggering onClick
events on my view)
class TouchListener(context: Context) : MultiTouchListener() {
private var tochedView: View? = null
private var mGestureDetector = CustomGestureDetector()
private var gestureDetector: GestureDetector = GestureDetector(context, mGestureDetector)
@SuppressLint("ClickableViewAccessibility")
override fun onTouch(view: View?, event: MotionEvent?): Boolean {
val aux = super.onTouch(view, event)
tochedView = view
gestureDetector.onTouchEvent(event)
return aux
}
private inner class CustomGestureDetector: GestureDetector.SimpleOnGestureListener() {
override fun onSingleTapUp(e: MotionEvent?): Boolean {
// this will be called even when a double tap is
tochedView?.performClick()
return super.onSingleTapUp(e)
}
override fun onSingleTapConfirmed(e: MotionEvent?): Boolean {
// this will only be called after the detector is confident that the
// user's first tap is not followed by a second tap leading to a double-tap gesture.
tochedView?.performClick()
return super.onSingleTapConfirmed(e)
}
}
}