You can also set it in your layout xml using the android:onclick attribute.
android:onClick="onClick"
Then in your activity class add the onClick method.
public void onClick(View v) {
...
Here’s the documentation.
More Related Contents:
- Android: Using findViewById() with a string / in a loop
- How to know which Button was pressed recently among all the Buttons in an activity?
- Application crashes at the startup. [closed]
- Android: combining text & image on a Button or ImageButton
- Android ImageButton with a selected state?
- Coloring Buttons in Android with Material Design and AppCompat
- Call method when home button pressed
- Android setOnClickListener method – How does it work?
- Best practice for defining button events in android
- How to disable / enable dialog negative positive buttons?
- Event OnClick for a button in a custom notification
- Android : How to update the selector(StateListDrawable) programmatically
- How to open the options menu programmatically?
- android set button background programmatically
- ListView and Buttons inside ListView
- How to handle Back button with in the dialog?
- How to create custom shape button with selector in android?
- How to bring view in front of everything?
- Dynamically creating Buttons and setting onClickListener
- How to detect “Recent Apps” system button clicks (Honeycomb+)
- Add an array of buttons to a GridView in an Android application
- Single click and double click of a button in android
- How to add button in ActionBar(Android)?
- how to change background image of button when clicked/focused?
- Cannot lower case button text in android studio
- Can I click a button programmatically for a predefined intent?
- OnItemClickListener doesn’t work with ListView item containing button
- Android Button setOnClickListener Design
- Detecting physical Menu key press in Android
- Capture button release in Android