Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

120
Views
RecyclerView on drop

I have RecyclerView Drag & Drop feature, but I'd like to do some calculations onDrop. When I put my expensiveFunction() in onMove() it's triggered at every position change until the drag is over. That's a big overkill. Is there a way to trigger function on drag end?

val itemTouchHelper = ItemTouchHelper(simpleCallback)
itemTouchHelper.attachToRecyclerView(recyclerView)

private var simpleCallback = object : ItemTouchHelper.SimpleCallback(ItemTouchHelper.UP.or(ItemTouchHelper.DOWN), 0) {
    override fun onMove(recyclerView: RecyclerView, viewHolder: RecyclerView.ViewHolder, target: RecyclerView.ViewHolder): Boolean {
        val startPosition = viewHolder.absoluteAdapterPosition
        val endPosition = target.absoluteAdapterPosition

        Collections.swap(itemList, startPosition, endPosition)
        recyclerView.adapter?.notifyItemMoved(startPosition, endPosition)

        expensiveFunction()

        return true
    }
}
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You could override onSelectedChanged() which get called when the ViewHolder swiped or dragged by the ItemTouchHelper.

To catch the drop action examine the actionState value to be ItemTouchHelper.ACTION_STATE_IDLE:

override fun onSelectedChanged(viewHolder: RecyclerView.ViewHolder?, actionState: Int) {
    super.onSelectedChanged(viewHolder, actionState)
    when (actionState) {
        // when the item is dropped
        ItemTouchHelper.ACTION_STATE_IDLE -> {
            Log.d(TAG, "Item is dropped")
        }
    }

}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!