Hey guys, welcome back to another video. And today I want to be sure you guys had to add a button in Android studio. And in this video, I want to be showing you guys three ways. Not just one. I'll just get started by first opening Android Studio after it's open. Let's create a new project. Let's create an empty views activity, but you can do whatever you want those great activity and let's call it button demo. And what do you spell Jabba baby at 29? That should work and I'm going to use groovy. Okay. Now the next step you just wait a few moments as your great old sinks and everything else and once it's done, it should look like this but before anything starts, I'm going to start my emulator. If you don't have what you can create new virtual device and create some phone like right here. I'm using you for the system image and then just press finish and you're good to go. I have a couple here. So I'm going to click on one and start it up and while that starting up for going to go to our code and we're going Go to activity main XML and if you don't know where to find that if it's not up here, you can go to Red's on the side and then under a layout. It should be right here and look like this if this is the right here on the sign, it'll look like this year and this is a constraint view which can be a little Annoying if you're new to address to use for the Richmond vs view who all live in your layout and we have some texture as you can see if we zoom in Jesus helloworld up there might be a little blurry, but that's okay because you said id up here or if we click up here you can split this or just look at the code and this code makes up like our design. So we're going to change this text to click button and under this we're going to have a button. So we're going to go back to this view by clicking this and we're going to drag in this button right there as you guys can see where it might not look that good as and design-wise because it's like pushing each other together. We can fix that if we go on our lender your way out here right quick convert orientation. And now it's still might not look that good but we can fix that. If we go over here into our code the first what I want to do is I want to set the padding on everything at the very top to 16 BP so you can see every kind of like zoomed in a little bit in his kind of like big over here. So we're going to remove that by removing this layout wait down here and should go back to normal and we can set the lamp to Center in Dutchess Center and then we can also do that up here or are click Button as a pattering we can put this up to like 56 and that's like good enough. I guess who have click button and then a button down here. That's and we're going to name it with me. That's the Texas going to appear down here for a button and you guys can see we have some ID here. This is like how we're going to refer to it in a Java code R button is called button or when I call this with me button and this over here are texting does not have an ID. So we're going to give it an ID of Text uhm one. I mean, it could be anything but we're just going to call or text one and now we're going to go to road traffic code. And first we're going to create some of these things that we have here. So we have a text for you and have a button you were going to add those here. So we'll make up a private text you text you and a private button button now, it's okay guys. If it's red we can just all enter on it or just hover over it and import the classes and the air should go away and then in your on create which is what runs out for you to your app starts. We have to accept these to the right IDs or five you the ID and there are no ID. And then put the ID and that was text one for the text. And then we're going to have to do the same thing for our friend but with our buttons ID and these might show red, but you can just ignore that. It's just Android Studio being bad and annoying. So the next step is that if we ran this right now, you're going to notice nothing. I want to click the button. That's okay. In order to make it work. We can go here on her button and we're going to create a class first class listener implements view on the glistener. What is why do they do that on click listener listener and go like that and I'm going to import that and then go over and Implement method they okay and it'll generate this method down here and this cold right here will run when the button is Click do and if we want that to actually work you have to go under button going to call button and set on Sleepless in her and we're going to write listen to her cuz that's the listener we gave it all this won't work because we have to make a new object so we can just go with new listener and then put that right there and then are on click we can say text you. Set text button has been licked and if we do that and we run her cuz we're going to notice it's going to work and we're going to be able to click the button. It's going to change the text. Okay guys, so the code has run by pressing the wrong button up here. And now it's on the phone if I click this button has been changed to the vine has work, but that's only one three way so we can do this the next way we can do. This is where we see that on click listener. What if we first, this out or not using this now and in here, please put clothes spaces. So you guys can see better. We write new onclicklistener. So this is like the egg is literally the exact same thing as this and this but now it's like leftovers unit. We don't have to make a separate class down here. We can just do it right here with their button and this is the exact same thing and we work the exact same and you can make it even simpler if we replace was Lambda and it's literally the simple now it's a one-liner we're going to go back and leave it like this. So you guys can see that and for the third way we're going to first comment this out and then down here. We're going to create a new map. All public void my listener or doesn't matter what you call it when you called my listener, or I think I spelled it wrong doesn't matter and read a view view right here as arguments and down here. We can run this code that we wanted to run before and it'll work the exact same way. Now as this coat is right now nothing will happen. But we have to go back for a some Oar button. We had a new thing called on click and butterless her name and and so this listeners the same thing that we were over here and if we run this code you're going to see it's going to work though. Let's click the button and it's clicked. Ok a lright guys, Adios (bye!)