Handling button clicks:
To handle button clicks in Android, we have 3 ways. Here, we will go for the first way.
i.e. in XML, we have an attribute called android:onClick, which takes a string as input with method naming convention. Whatever the method name we will provide in that, we need to create the same method in Activity class with the following signature.
public void methodName(View view{
|
| // All the logic to execute on clicking button
|
}
Ex: in XML
<Button
android:id=”@+id/submit_btn”
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:onClick=”onSubmitClicked”
android:layout_gravity=”center”
android:text=”Submit” />
the above thing can be handled in Activity as follows
in Java
public void onSubmitClicked(View view) {
}