0

I've a RecyclerView implemented with a GridLayoutManager, something similar to an Image Gallery. I'm trying to implement a drag select behavior on it using this library.

I want to activate the drag selection on a long press of a view holder. Below is the sample activation code for the library.

touchListener.setIsActive(true, index) // index = start position of the view holder in the grid

Issue:

I implemented the OnLongClickListener on the ViewHolder but how do I get the position of the view in the grid?

class ImageViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnLongClickListener {
    override fun onLongClick(v: View): Boolean {
        ImageFragment.activateDragSelect(0) // Calls the above activation snippet
        return true
    }
}
Siddharth Kamaria
  • 2,448
  • 2
  • 17
  • 37

1 Answers1

1

You can have to position of your ViewHolder with:

getAdapterPosition()

Raida
  • 1,206
  • 5
  • 17