Using the layout to define a click action
suggest changeWhen 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.
}
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents