I implemented a swipe left to delete action in my recycler view like below:
ItemTouchHelper
public class SwipeToDelete extends ItemTouchHelper.SimpleCallback {
//my custom adapter
private MyAdapter slAdapter;
public SwipeToDelete(MyAdapter adapter){
// TO only swipe to the left
super(0, ItemTouchHelper.LEFT);
slAdapter = adapter;
}
@Override
public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
int position = viewHolder.getAdapterPosition();
slAdapter.deleteItem(position);
}
}
MyAdapter
public class MyAdapter extends RecyclerView.Adapter<MyAdapter.MYViewHolder> {
//... onCreateViewHolder .. etc
//creating a list of my custom layout view
private List<MyCustomCardView> cards;
public void deleteItem(int position){
cards.remove(position);
notifyItemRemoved(position);
}
}
With simply that, I am able to swipe and delete views in my recyclerView.
What I would like to do is to stop the swipe halfway and show an icon. The user can then either click the icon and the swipe continues and deletes the view, or else continues the swipe himself/herself and the view will be deleted.
As it is right now, the user can just barely swipe left and the swipe automatically continues, I would like to have an intermediary step which shows an icon that is clickable. How can one do that with the above code?