I am not changing anything in your code just i am providing you a way to get it correctly as you are missing lot of things
Button's onClick() method can be set up basically in 3 ways
Very first from xml side when you declare a button
<Button
android:layout_height="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:onClick="login"/>
And then just make a method in associated java class with the same name as given in XML file like this
public void login(View v)
{
//do whatever you want here
}
Second way you can make an inner implementation anywhere in your class by simply making onClickListner() on Button,but you have to make sure to get button on java side by findViewById() method once you got it then you can set like this
Button b = (Button)findViewById(R.id.button);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//do stuff here
}
});
third way is also simple you can implement OnClickListner in your whole class and then you can use it for multiple views clicks but i would say if you have a button only then no need to use this you can use above two methods in this one you can do this
b.setOnClickListener(this);
It will show you an error that methods are not implemented and then you can just use Alt + Enter and onClick() method will be implemented
@Override
public void onClick(View v) {
if(v.getId()==R.id.yourId) {
//do stuff here
}
}
Some useful links are below
Best practice for defining button events in android
Difference between OnClick() event and OnClickListener?
Button Click Listeners in Android