Skip to content

Instantly share code, notes, and snippets.

@vshkl
Created November 15, 2020 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vshkl/08cebff7e916f4da01227caeffbc576a to your computer and use it in GitHub Desktop.
Save vshkl/08cebff7e916f4da01227caeffbc576a to your computer and use it in GitHub Desktop.
class MainSimpleOnItemTouchListener(
private val listener: OnInterceptTouchEventListener
) : RecyclerView.SimpleOnItemTouchListener() {
interface OnInterceptTouchEventListener {
fun onInterceptTouchEvent(touchedPosition: Int)
}
override fun onInterceptTouchEvent(recyclerView: RecyclerView, event: MotionEvent): Boolean {
val childView = recyclerView.findChildViewUnder(event.x, event.y)
val touchedPosition = childView?.let { recyclerView.getChildAdapterPosition(childView) } ?: -1
listener.onInterceptTouchEvent(touchedPosition)
return false
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment