‫So we are going to add the swipe functionality and capability for the recycler views.
‫First of all, I will go to the gradle.
‫I will add a dependency here.
‫Oops, it's happening.
‫And it is implementation.
‫And this is a library for swipe reveal of the layout.
‫Okay.
‫Everything is working fine.
‫Waiting for gradle to sync.
‫Now I will make a layout here.
‫Layout resource file, I will call it item underscore employee swipe.
‫So it will add the functionality.
‫For this layout for the sake and the purpose of making everything fast and making coding a little faster
‫and more interactive.
‫I will copy and paste the the layouts in order to save time, so I will paste the layout here.
‫Okay, so I have a layout of this library having same level as mode drag edge to the right which enabled
‫the swiping.
‫Now I will design here two layouts, the swipe layout and the mania.
‫So when the user didn't swipe anything, this main layout will be displayed having only a text view.
‫Okay.
‫It's very simple.
‫When the user swipes them the layout or the item, there is a text view here called edit and a text
‫view also here called delete.
‫So in this way we have two text views will appear delete and edit when the user swipe the.
‫All right.
‫So as I told you, this layout will have swipe layout and the main layout, and it's inside this library.
‫So this is the layout.
‫If you want, you can download the source code from below.
‫And you can pause the video and copy this layout.
‫Okay.
‫Now.
‫Let's go and make the same as that we have done before in the previous videos.
‫I will create a new package here.
‫I will call it Swipe, and inside the swipe I will create a new activity.
‫And the activity I will call it swipe selection here.
‫Swipe
‫selection activity.
‫Okay.
‫It's working.
‫I will implement the Or import the class and everything should work fine.
‫This is the layout of this activity.
‫The layout of this activity will contain only a recycler view.
‫So I will drag and drop a recycler view here.
‫I will add the the constraints for it.
‫And I will add an ID for it.
‫I will call it swipe, swipe, underscore.
‫Okay.
‫Everything should work fine now.
‫As I told you before, we need an adapter.
‫And a model class and a custom layout.
‫So first of all, I will create an adapter.
‫Adapter, I will name it as swipe.
‫Adapter.
‫But before we continue with making this adapter, let me don't miss making a button because maybe we
‫will miss it.
‫Uh, I will go to the main activity.
‫Drag and drop a button here.
‫Okay.
‫I will add the constraints for it.
‫I will give it an ID button.
‫Underscore swipe.
‫Okay.
‫Refractor.
‫And everything is working fine.
‫I will give it a text view.
‫A text?
‫Sorry.
‫Inside it called.
‫Recycler view
‫with swipe.
‫The swipe.
‫Swipe.
‫Right.
‫Athens.
‫Okay.
‫Everything is working fine.
‫I just need to make a button here in order to add intent and allow us to move to the.
‫For the next.
‫Activity.
‫I copy this.
‫Put it five here and here I will name it.
‫Swipe three.
‫Button, swipe or swipe swipe buttons.
‫And it will give a go us or direct us to swipe.
‫Selection activity.
‫Now we have done with the main activity.
‫Now let's concentrate on the recycler view.
‫The swipe selection activity.
‫The view as the swipe adapter and the custom layout that we have created.
‫Now in the swipe adapter.
‫I need to concentrate with me guys, because this adapter, it will differ slightly, slightly than
‫the before adapters that we have done in the previous activities.
‫The swipe adapter will extend Recyclerview dot adapter because we are going to make a custom adapter
‫and I will make a swipe adapter dot swipe.
‫View.
‫Holder This view?
‫Holder We are going to create in this class.
‫So as I told you guys, it's very important to understand how to make a custom add a custom adapter
‫for recycler view and the custom view for circular views.
‫The first step is making Making Swipe adapter
‫constructor and implement implement the methods.
‫So and the second step is making the view holder, which I will name it, swipe view holder.
‫You see, guys, we are making a custom view holder that above will have inside this view this class.
‫It will contain a swipe holder swipe view holder that we are going to create.
‫But as as I told you.
‫We start by second step because I prefer it because maybe we have some errors if we start by step one.
‫Due to the implementation of some unbind viewholder and in oncreate viewholder methods will make and
‫implement the wrong statements.
‫So I prefer making it first.
‫So swipe viewholder extends I will extends recyclerview.
‫Dot view holder and inside this view holder I will create here.
‫Private.
‫Text view.
‫Sorry.
‫This happening.
‫Text to you.
‫Text of you.
‫I will name it text of you.
‫Private text of you also.
‫It is text for edit.
‫And I will make private text of you text for delete.
‫We see guys in the custom layout that we have created as a as a remembering for you and as a note for
‫you.
‫Here we have the mainly out.
‫It will display a recycler text sorry, text view and when the user swipe it it will display an edit
‫and delete text view.
‫So we are going to initialize them here.
‫Okay.
‫So.
‫And a private swipe reveal layout.
‫I will call it as swipe reveal layout.
‫I will make a constructor.
‫Having.
‫None.
‫Select none.
‫And.
‫I will copy them here in order to save time.
‫I import the class and swipe.
‫Swipe, layout.
‫Swipe reveal.
‫So these are the.
‫Us now.
‫I will add here our handling handling the Click listeners or handling the click events on the text views.
‫So when the user click, text, edit or text edit, it will display a toast message for it.
‫So we use set on click.
‫Listener new view on Click Listener and it will make a toast message telling him hey you clicked.
‫Edit So context we will make it in the first step so I will make it here.
‫In the first step, making the swipe adapter.
‫I will make the context later on.
‫Edit as clicked and the same way I will make for the delete.
‫So when the user click this text views.
‫A text message will be here.
‫You can put here whatever you want to be executed when the user clicks.
‫But for sake of of making everything simple.
‫We have choose this.
‫I will create a method here called bind data
‫Having a parameter employee employee
‫Text view.
‫Dot set text.
‫So employee dot get name.
‫Okay.
‫Everything should work fine.
‫Okay, guys.
‫Now let's move to the first step.
‫Okay.
‫Don't miss to name the context as this.
‫This is the first step.
‫The second step.
‫Sorry, we have done.
‫Now let's move to the first step.
‫Private, as I told you.
‫Start the context.
‫Context errors has been solved.
‫Now, private.
‫Array list of type or passing the generic as employee employees
‫and private
‫final view.
‫View binder help.
‫This is the new thing that we are going to learn in this video.
‫View Binder Helper.
‫We are going to use a view binder.
‫Binder helper in order to to succeed in making the swipe and using the bind method below and when the
‫user closes the layout.
‫Open the layout.
‫Bind the view and bind the data.
‫This is the main things that we are going to use the view binder helper for it.
‫We are going to use it on bind viewholder.
‫So.
‫Till now.
‫Let's make the constructor here.
‫Constructor Having like this?
‫And I need to make private set employee void.
‫Void set employees.
‫ArrayList.
‫Of employees.
‫Please.
‫This.
‫Employees.
‫Equal new array list.
‫This employees equal employee and notify dataset change.
‫Till now, everything is working fine as as we have seen before.
‫But this is the new thing that we have learned in this video and we are going to work with.
‫So the the last step here is implementing the methods.
‫So we have created the constructor and now we are going to implement the method, click on the, implement
‫the methods, and everything is working fine.
‫So I told you to start by step number two in order to prevent here some errors and Android studio will
‫import the wrong package and the wrong names of these classes and and implement and this will make errors
‫for you.
‫Now a view view are called view.
‫Layout inflator from context.
‫That.
‫Inflate.
‫All dot layout dot item swipe.
‫So this is the layout that we have created and it is a custom layout.
‫Parent and false.
‫And we are going to return
‫new swipe viewholder and the passing view.
‫Okay.
‫I will put here employees dot size and we come to the important part here.
‫In order to use the swipe bind binder Viewholder.
‫So guys, we start by view binder helper dot set open only one and we come make it through and view
‫binder helper dot bind.
‫This is the method and I will pass.
‫Asswipe.
‫This is the swipe holder or holder.
‫Dot swipe.
‫Lay out.
‫It says this will play out.
‫And a string.
‫Dot value of.
‫And I will get the employees dot.
‫Get I and I will get and I or position and I will get the name.
‫So in this way we are going to pass to the bind the bind method that we have created here.
‫Sorry.
‫The bind.
‫Bind.
‫The bind method that this contains.
‫So this is a view binder helper contains a method called bind.
‫We need to pass a layout of type swipe reveal layout, and we need to pass a string.
‫For it.
‫So these are the two parameters.
‫This is the one that we have created and we are getting the value of the employees and the name of employees
‫array list.
‫Now Viewholder Binder.
‫View Binder Helper Dot Close Layout.
‫And on enclose.
‫I need to make a string, a pass a string and get the value of in the same way employees dot get I and
‫dot get name I means position.
‫So copy.
‫Changing it to position.
‫Now swipe viewholder all order dot bind data and I will pass employees dot get position.
‫Okay.
‫And this way we have set our layout.
‫The adaptor correctly and we have used the viewfinder hump.
‫So when the user opens, it will display a reveal layout and when the user close, it will display a
‫string.
‫And this is the value of it.
‫Okay, It's very simple.
‫Now let's move to the main layout of this swipe selection activity.
‫The main activity of this recyclerview and I will create recyclerview.
‫Let's initialize some widgets.
‫Recycler View and swipe adapter.
‫Adapter and I will create.
‫ArrayList.
‫Passing employees.
‫Employees equal.
‫New array list.
‫Okay, so.
‫Let's initialize the widgets.
‫Recyclerview Equal.
‫Findviewbyid.
‫Dot id dot swipe.
‫Part of.
‫Recyclerview.
‫I will copy them from the previous video here and I will pasted them because we have we have talked
‫about them many times.
‫So this is.
‫Forsake of making everything fast.
‫I will create a method called create list.
‫I will create it here.
‫And inside the create list.
‫I also will copy it because I have done it before in the previous video and lectured it in the previous
‫two videos.
‫Previously done videos.
‫Okay, so adapter dot set.
‫This is the adapter.
‫I will make it as private.
‫Maybe it is making.
‫Some errors.
‫This is great list.
‫Adapter dot set employees.
‫I will go to the adapter.
‫I have maybe missed this.
‫To the adapter.
‫Set employees.
‫Okay.
‫It is this.
‫This is the method.
‫And this is the method.
‫Okay?
‫It is private.
‫I will make it as public.
‫And here we go.
‫We have Everything worked.
‫Okay.
‫This is a dummy.
‫A dummy list of employees just making.
‫Employee one.
‫Employee two Employee three till 19.
‫And we are going to set the adapter.
‫Now let's close everything and try to run.
‫For.
‫And here we go, guys.
‫This is our recycler view application.
‫We click on recycler view swipe items.
‫And these are the items, the mock example that we have created.
‫And we see we have implemented the swipe capability and functionality correctly in this recycler view.
‫So if the user clicked edit a toast message will be.
‫Appear and delete and delete, it is clicked.
‫So this is the example of our recycler view.
‫Using the swipe actions.
‫So thank you guys.
‫I hope you rate us five stars on Udemy.
‫And subscribe to our YouTube channel Master coding.
‫Now let's move to another.
‫Recycler view and making a multiple view types.
‫This is the most advanced and complicated ones.
‫See you in the next video.