Using the layout to define a click action

suggest change

When we create a button in layout, we can use the android:onClick attribute to reference a method in code to handle clicks.

Button

<Button
    android:width="120dp"
    android:height="wrap_content"
    android:text="Click me"
    android:onClick="handleClick" />

Then in your activity, create the handleClick method.

public void handleClick(View v) {
    // Do whatever.
}

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents