I have a blank activity in Android Studio, and I have performed the following instructions but it is not working when I run the program.
- Select the button and look for properties/attributes panel on the right.
Assign the name onClick to the android:onClick property of your Button.
Implement the following method in the Main_Activity file:
public void onClick (View view) {
Toast.makeText(this, "Button 1 pressed", Toast.LENGTH_LONG).show();
}
When I try to run this I get errors like:
- expecting a member declaration
- function declaration must have a name
1)in Xml file of you Activity set onClick property of button with specified function name android:onClick:"onClick"
2)after this put same function inside your activity but with parameter like this public void onClick (View view)
3) when you click on button provided method gets called
Note: function name can be anything but access specifier, return type and parameter has to be same.