The Wayback Machine - https://web.archive.org/web/20240204231449/https://www.geeksforgeeks.org/android-app-to-add-two-numbers/
Open In App
Related Articles

Android | App to Add Two Numbers

Improve
Improve
Improve
Like Article
Like
Save Article
Save
Report issue
Report

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

  • STEP-1: First of all go to the xml file
  • STEP-2: Now go to the text and write the code for adding 3 TextView,2 EditText and Button and Assign ID to each component. Assign margin top, left, right for the location.
  • STEP-3: Now, open up the activity java file.
  • STEP-4: Declare 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.
  • STEP-5: Add the click listener to the Add button.
  • STEP-6: When the Add button has been clicked, add the values and store it into the sum variable.
  • STEP-7: 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. 

activity_main.xml

 

MainActivity.java

 

After Complete layout xml file it will be shown as given below Output: Note: Similarly, Android App to subtract, multiply and divide numbers can be made by making minor changes in the Java and XML code.

Ready to embark on an exciting journey into the world of Android Development with Kotlin? It's time to make a change and dive into a fantastic learning experience with our Mastering Android Development with Kotlin From Beginner to Pro - Self Paced!


Last Updated : 01 Nov, 2023
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads