How to Make a Calculator App for Android

Hello everyone, in this tutorial we are going to learn how to make a calculator app for android (using Eclipse). Step by step process is given in this article that will help you to make a simple calculator in very easy way.

You can also download the apk file and use it as a normal app in your android phone.

 

Steps to Make a Calculator App for Android

1. First of all open eclipse (If your are new to android programming then go to http://developer.android.com/sdk/installing/installing-adt.html to download and configure android development tools).
 

2. Create a new project > Select Android Application Project > Now name your project “Calc”. 

 How to Make a Calculator App for Android
 
3. Choose a Package Name. A Package Name is a unique URL of your Application. In most cases it is the inverse of your website. For example: com.thecrazyprogrammer.appname
 

4. If you want you can leave it to the default package name which is “com.example.calc”. Now hit next two times. 

How to Make a Calculator App for Android

 

5. If you have made an Icon then add it otherwise go with the default one. Select Blank Activity > Now name your activity “GUI”. 

How to Make a Calculator App for Android

 

6. From Palette option add total 16 buttons & name them from 0 to 9 and +, -, X, /, ., =. 

How to Make a Calculator App for Android

 

7. After completing this go to Package Explorer & under your Package Explorer Select src > Your package Name > yourActivityName.java 

How to Make a Calculator App for Android

8. Open the java file and paste the given code:

9. Right click on your project and select run as Android Application . Now the emulator will pop up & you can test your project.
How to Make a Calculator App for Android
10. Download the calculator app for android from below link.

If you liked the tutorial then don’t forget to comment and share!

25 thoughts on “How to Make a Calculator App for Android”

  1. Int will store only non decimal values and if you are using divide and . in your calculator you should use double :). Just a view, not saying you have done it wrong.

    1. Hello md. imran please help me for android app develope,,
      how to start developing,,,
      i am presuing BCA
      in this time i am learning c.
      but i want to know android developing..

      1. Not only that it will display blank as the string is set null (i.e. ” “), if we insert “+”,”2″ or any digits it will display that.

  2. your program is very clear.. but I didnt get the output bcos it gives the result as 0 for all the operator… seems lyk something is missing… clear it plz….

    1. may be the id for each content is not good…or its matchi ng…u should check id of each content either its a button or textfield

  3. app got chrashed during entring value -20 or dividing any value by 0 eg 5/0 . there is no exception handling for this hence a bad code

  4. i followed these steps but answer is nothing…so plz add more step for every step..and check the code…if i have some problems in coding then how to solve this my self?some red signal makes under the code self…how we can removed ….plz help me and all of..

  5. I took 16 buttons and then in my XML file,I assigned 0 to 9 and then +,-,*,/,.,=
    but they are not working properly i.e,if I am clicking on 2 button but it is performing different operations

  6. This tutorial was very helpful to build my basics. I was able to build my own app for Play store. Thank you Sir.

  7. This is great way to start your android programming.But with this code,You can’t use your dot operator and even if you change your operands to Double or Floats then you cannot do more than 1 calculation in the calculator.Example you want to add 12+1 that would give you 13.0 but now if you want to add 1 more to this 13.0 without pressing Clear,the application would crash.
    But this crash doesn’t happen when you are using integer types.

  8. Syed Mazhar Ali

    hi bro since your code dont follow operator precedence the result is incorrect in calculation of more than two numbers

Leave a Comment

Your email address will not be published. Required fields are marked *