Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
How can I show confirm dialog before deleting Recyclerview Item using ItemTouchHelper.
I have create RecyclerView and implemented basic ItemTouchHelper.Callback class. But, I don't know what to do next.

What I have tried:

I have created below class and attached it to Recyclerview. Swiping away item works. But I want to show confirm dialog even before the item is moved.

class SwipeController extends Callback {
   
    public SwipeController( ) {
       
    }

    @Override
    public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
        return makeMovementFlags(0, START);
    }

    @Override
    public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
       
    }
}
Posted
Comments
David Crow 2-May-18 11:53am    
"But I want to show confirm dialog even before the item is moved."

Can you put an AlertDialog in the onSwiped() method?
Yesudass Moses 2-May-18 16:21pm    
I can... but that doesnt prevent removal of items.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900