Android Swipe to Delete RecyclerView items with UNDUIn this tutorial, we will create the example to delete an item of RecyclerView by swiping the item with undo functionality. For this purpose, we will use ItemTouchHelper class which is added in Android Support Library V7. This class is used to create a swipe to delete the items of RecyclerView. It has a SimpleCallback class that configures the events which are performed to swipe or move the item of the RecyclerView. ItemTouchHelper classIt is a utility class which provides the facility to add swipe to dismiss and drag & drops the items of RecyclerView. It overrides the callback methods onMove() or onSwipe() depending upon the functionality we implement. Android Swipe to Delete RecyclerView items ExampleCreate a MainActivity.java class with the following code. activity_main.xmlcontent_main.xmlMainActivity.javaCreate a layout regular_item.xml which appears at normal mode. regular_item.xmlCreate a layout swipe_item.xml which appears at the period of swipe item. swipe_item.xmlcustomlayout.xmlCreate a utility class SwipeUtil.java which extends the ItemTouchHelper.SimpleCallback class and overrides its onMove(), onSwiped(), onChildDraw() methods. The onSwiped() method is called when we perform swipe operation on an item, and the onChildDraw() methods contain the implementation logic of drawing canvas while swiping the items of RecyclerView. SwipeUtil.javaCreate an ItemViewHolder.java class and extends RecyclerView.ViewHolder. ItemViewHolder.javaCreate an adapter class MyAdapter.java which extends the RecyclerView.Adapter MyAdapter.javaCreate a MainActivityFragment.java class and extends the Fragment class. In this class, set the adapter MyAdapter.java class and utility SwipeUtil.java class. fragment_main.xmlMainActivityFragment.javastrings.xmldimens.xmlcolors.xmlOutput: ![]() ![]() ![]()
Next TopicSwipe Refresh Activity
|
JavaTpoint offers too many high quality services. Mail us on h[email protected], to get more information about given services.
JavaTpoint offers college campus training on Core Java, Advance Java, .Net, Android, Hadoop, PHP, Web Technology and Python. Please mail your requirement at [email protected].
Duration: 1 week to 2 week