I have 2 files: main_activity.xml and home.xml. I made a button in main_activity.xml
Here is the code snippet:
You can use this code.
Android: OnClickListener
In our activity class we add the onclick method.
In our activity class we add the onclick method.
//On click event for button1
public void button1OnClick(View v) {
//Inform the user the button has been clicked
Toast.makeText(this, "Button1 clicked.", Toast.LENGTH_SHORT).show();
}
In the layout file we add a reference to the onclick handler in the activity. The app will automatically bind the onclick method to the view (in this case button1)