I am trying to use the SwipeDismissBehavoir
from design support library. I've list items in RecyclerView
and swiping an item have to dismiss (like google inbox app) .
I've set the listener for the RecyclerView
items but the SwipeDismissBehavior
onDismiss
listener is not getting called.
SwipeDismissBehavior behavior = new SwipeDismissBehavior();
CoordinatorLayout.LayoutParams params = (CoordinatorLayout.LayoutParams)mItemLayout.getLayoutParams();
params.setBehavior(behavior);
behavior.setListener(new SwipeDismissBehavior.OnDismissListener() {
@Override
public void onDismiss(View view) {
}
@Override
public void onDragStateChanged(int i) {
}
});
mItemLayout.setLayoutParams(params);
I have succeeded implementing the support library SwipeDismissBehavior and it actually requires CoordinatorLayout inside of each inflated card view layout. I haven't noticed any performance issues so far, so I assume CoordinatorLayout is not so heavy for the UI. There is probably a better way, but I still haven't found it.
In the constructor of the RecyclerView.ViewHolder implementation class (which is inside the Adapter) I have added:
Here is example how delete row by swipe
MainActivity.java
Adapter
Layout
Item in RecyclerView
Tried with single view. I can know the view was dismissed, but I'm wondering how to restore the view like Gmail.
Layout:
Activity: