VOOZH about

URL: https://www.geeksforgeeks.org/android/android-app-to-add-two-numbers/

⇱ Android Application to Add Two Numbers - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Android Application to Add Two Numbers

Last Updated : 11 Jul, 2025

Below are the steps for Creating a Simple Android Application to Add Two Numbers

Note: Similarly, Android App to subtract, multiply and divide numbers can be made by making minor changes in the Java and XML code.

Step-by-Step Implementation of Application to Add Two Numbers in Android

Step 1: Opening/Creating a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

Note: Select Java as the programming language.

By default, there will be two files activity_main.xml and MainActivity.java.

Step 2: Now go to the activity_main.xml file and Add elements to the layout

Here, we are using constrainLayout in our application where we will be using Constraints and Chaining concepts.

Navigate to activity_main.xml file:

👁 activity_main_Java

Complete code of layout xml file is mentioned below:


After Complete layout xml file it will be shown as given below :

👁 Add_Two_Numbers

Note: The Layout of Android Application differ for all. Although the elements will be same for all.

Step 3: Now, open up the activity java file.

Navigate to MainActivity.java file is mentioned below:

👁 MainActivity

Step 4: Changes are done in Java MainActivity file

  • Declare a few variables and the values entered in the Text Views can be read by using an id which we have set in the XML code above.
  • Add the click listener to the Add button.
  • When the Add button has been clicked, add the values and store them in the sum variable.
  • To show the output in the result text view, set the sum in the TextView.

Complete code of layout xml file and java file is given below. 

Output:

👁 Output_of_sum_of_two_numbers

Note : To access the full android application check this repository: Add Two Numbers Application

Comment
Article Tags:

Explore