I have a RecyclerView with 2 items that don\'t fill the whole screen. How can I detect that the user clicked on the empty part of the RecyclerView (meaning clicked directly on t
@Angel Kjoseski answer would look like this in Kotlin:
yourRecyclerView.addOnItemTouchListener(object : RecyclerView.OnItemTouchListener {
override fun onInterceptTouchEvent(recyclerView: RecyclerView, motionEvent: MotionEvent): Boolean {
return when {
motionEvent.action != MotionEvent.ACTION_UP || recyclerView.findChildViewUnder(motionEvent.x, motionEvent.y) != null -> false
else -> {
// do something here
true
}
}
}
override fun onRequestDisallowInterceptTouchEvent(disallowIntercept: Boolean) {}
override fun onTouchEvent(recyclerView: RecyclerView, motionEvent: MotionEvent) {}
})