Android button

Working with Button: Android Button Example

A push-button is represented by the Android Button. The TextView class has an android.widget.

Android Button Example with Listener:

The below example is to create two text fields and one button to display the additional result of two numbers.  button or adding the onClick property of a button in the XML file of the activity.

Drag the component or write the code for UI in activity_main.xml:

Here, we will drag two text fields from the Text Fields palette and one button from the Form Widgets palette.


<EditText android:id=”@+id/editText1″ android:layout_width=”wrap_content” android:layout_height=”wrap_content” android:layout_alignParentTop=”true” android:layout_centerHorizontal=”true” android:layout_marginTop=”61dp” android:ems=”10″ android:inputType=”number” tools:layout_editor_absoluteX=”84dp” tools:layout_editor_absoluteY=”53dp” />