
For that we use setOnClickListener() function.

So for that we need to define these operation over button click. This calculator app basically perform five operations i.e addition, subtraction, multiplication, division and reset. The interface part of the application is over, let’s focus on adding functionality to the application. Step 4: Open src -> package -> MainActivity.java. So now we have designed the complete UI of the Calculator App. The complete interface code of activity_main.xml:

Iii of Step 3 – Further in continuation with previous linearlayout add a textview, textfield(Number) for displaying result which makes the interface complete. This code will be inserted in main layout: in it and close the linearlayout.įollowing code of activity_main.xml. Ii of Step 3 – Then before closing the above layout define another layout as Linearlayout horizontal, add five button ( +, -, *, / and Clear) define their properties like id, width, height etc. I of Step 3 – Create a Linearlayout vertical, add a textview followed by two textfields Number(decimal) for writing numbers in it.

Here we are going to create the application interface like add layouts, Button, TextView and EditText. Step 3: Open res -> layout -> activity_main.xml (or) main.xml. Step 2: Create a new project and name it Calculator.
