I use RecyclerView with ItemTouchHelper to do swiping to remove, and add delete button under the swipe item like this:
But when I finish swiping, the item will be removed from the list soon! How can I lock the swiped item, and removed by clicking the delete button? Just like Gmail's behavior.
ps. I post same issues here https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=&colspec=ID%20Type%20Status%20Owner%20Summary%20Stars&groupby=&sort=&id=189057
1 Answer. Show activity on this post. float newDx = dX; if (newDx >= 100f) { newDx = 100f } super. onChildDraw(c, recyclerView, viewHolder, newDx, dY, actionState, isCurrentlyActive);
Android Swipe To Delete. Swipe to delete feature is commonly used to delete rows from a RecyclerView. In order to implement Swipe to delete feature, we need to use the ItemTouchHelper utility class.
A ViewHolder describes an item view and metadata about its place within the RecyclerView. RecyclerView. Adapter implementations should subclass ViewHolder and add fields for caching potentially expensive View. findViewById(int) results.
@Override
public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
float translationX;
if(dX > 0){
translationX = Math.min(-dX, viewHolder.itemView.getWidth() / 2);
}
else {
translationX = Math.max(dX, (-1)* viewHolder.itemView.getWidth() / 2);
}
super.onChildDraw(c, recyclerView, viewHolder, translationX, dY, actionState, isCurrentlyActive);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With