Answer the question
In order to leave comments, you need to log in
How to return onClickListener for child elements when using onTouchEvent?
Hello everyone, can someone help with custom scrollview, I needed to track when a person swipes left / right being at the end of the list to display the ui element (something like swipe to refresh layout is only horizontal and works in both directions) Used GestureDetector , swipes are tracked and everything is fine, but the scroll stopped listening to click events from child elements and I can’t figure out how to return it
. I store table cells in the scroll, each has its own click handler
override fun onTouchEvent(ev: MotionEvent): Boolean {
when (ev.action){
MotionEvent.ACTION_DOWN -> {
performClick()
x1 = ev.x
y1 = ev.y
}
MotionEvent.ACTION_UP -> {
val diffX = x1.minus(ev.x)
val diffY = y1.minus(ev.y)
if (abs(diffX) > abs(diffY)){
if (abs(diffX) > MIN_DISTANCE && FINAL_SCROLL_POS){
if (diffX < 0){
Log.e("SCROLL direction", "RIGHT")
scrollViewListener!!.onRightScroll()
}else {
Log.e("SCROLL direction", "LEFT")
scrollViewListener!!.onLeftScroll()
}
vibrate()
}
}
}
}
return super.onTouchEvent(ev)
}
override fun onInterceptTouchEvent(ev: MotionEvent?): Boolean {
return if (gestureDetector!!.onTouchEvent(ev)) true else super.onInterceptTouchEvent(ev)
}
Answer the question
In order to leave comments, you need to log in
In general, I fixed it, if suddenly someone encounters the same problem:
Remove the dispatchTouchEvent method, then simply override onSingleTapConfirmed and return false in it
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question