I am trying to implement swipe to delete the same as Gmail app "Swipe to archive":
I have tried many tutorials but none of them works as fast as gmail,
I prefer to not work on external library. How can i do it?
Edit:
My code so far-
ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
public boolean onMove(RecyclerView recyclerView,
RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
// final int fromPos = viewHolder.getAdapterPosition();
// final int toPos = viewHolder.getAdapterPosition();
// // move item in `fromPos` to `toPos` in adapter.
return true;// true if moved, false otherwise
}
@Override
public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
//Remove swiped item from list and notify the RecyclerView
mAdapter.notifyItemRemoved(viewHolder.getLayoutPosition());
}
};
ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
itemTouchHelper.attachToRecyclerView(mRecyclerView);
I've managed to enable swipe gesture but i don't know how to add a background and an image under the viewHolder. I tried to put another FrameLayout at the item_XXX.xml file but on swipe it throws the whole item with the background.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…