Skip to content

Instantly share code, notes, and snippets.

View Sagar0-0's full-sized avatar
πŸ›

Sagar Sagar0-0

πŸ›
View GitHub Profile
@Sagar0-0
Sagar0-0 / DragSelectionItemTouchListener
Created April 10, 2025 04:14
This Kotlin class implements a RecyclerView.OnItemTouchListener that enables drag-to-select behavior in a recyclerview grid. It tracks touch gestures, calculates item ranges, and triggers selection callbacks. Auto-scroll is supported when dragging near the top or bottom of the RecyclerView. Useful for enabling intuitive multi-item selection in p…
import android.content.Context
import android.content.res.Resources
import android.view.MotionEvent
import android.view.animation.LinearInterpolator
import android.widget.OverScroller
import androidx.recyclerview.widget.RecyclerView
class DragSelectionItemTouchListener : RecyclerView.OnItemTouchListener {
private var isActive = false
private var start = RecyclerView.NO_POSITION