Introduction: Android Development: Creating a Basic Calculator

Picture of Android Development: Creating a Basic Calculator

Welcome to a fun tutorial on making a basic calculator on an Android application. In this tutorial I will guide you through downloading all the necessary software, designing the layout of the application, coding the application to make it work properly, and finally how to run the application on an Android Virtual Device. 

Knowledge Requirements:
While creating the tutorial I assumed that the viewer already has a good understand of the JAVA language. In the tutorial I do not go into specific detail about the code I am writing besides a basic background of the new android parts. After watching many other Android tutorials however, I realized this is how many of the tutorial videos handle the JAVA knowledge.

Required Parts:
- Working Computer
- Windows / Mac / Linux OS
- Drive to learn
- Android Device (OPTIONAL)

If any questions arise during the 10 part video series, make sure to go to the final step in order to find my contact information that will allow me to personally address your question to provide you with a solution in a timely manor. 


Resources:
I have attached the two files that we were coding with during these tutorials. If for any reason you get lost while following a long or can't figure out an error, these will be a good place to look since they contain the working code of the application.

Step 1: Step 1: Download Java JDK

In this step I will guide you on how to install the Java JDK to your machine in order to correctly run the java code you will compile in later steps.

Step 2: Step 2: Download Android SDK

In this step I will go over how to download the Android SDK to provide you with the tools needed to develop your first Android Application. These tools include the AVD manager, the Eclipse development environment, and multiple plugins that will be used in the background.

Step 3: Step 3: Setting Up AVD (Android Virtual Device)

In this step I will go over how to set up a AVD (Android Virtual Device) in order to run your code on in future steps. Once you successfully create your AVD and it is starting up, I suggest moving onto the next steps since the boot time takes roughly 10 minutes. You will not need it booted up until step 10 so you will have plenty of time.

Step 4: Step 4: Setting Up Eclipse Environment

In this step I will go over how to set up the Eclipse development environment to get you started on programming your first Android application.

Step 5: Step 5: Creating Textviews for Layout

In this step I will go over how to design and set up the input and output textviews that you will be using in your Android Application.

Step 6: Step 6: Creating Buttons for Functionality

In this step I will go over how to create and design the buttons that you will use in your Android Application.

Step 7: Step 7: Setting Up the Main Activity Java File

In this step I will go over how to set up the main activity java file that you created in step 4. This code will be the background code for your program and will allow the buttons and textviews to function properly.

Step 8: Step 8: Making the Buttons Function Correctly

In this step I will dive further into the main activity java file to show you how to get the buttons to do the necessary calculations with the input values based on which button you pressed.

Step 9: Step 9: Outputting the Results

In this step I will finish off the main activity java file by outputting our results to a textview that we created in step 5.

Step 10: Step 10: Running the Application

In this final step I will go over how to run the completed Android application on the AVD that we set up in step 3. Once you have finished this step and successfully ran the application, you have completed your first Android tutorial!

Step 11: Conclusion & Contact

Thank you for following a long with my Basic Android Calculator tutorial. I hope you guys enjoyed the 10 part video series and learned a little more about development in Android. If you want to dive further into programming with Android I suggest thenewboston's tutorials on YouTube. This series provides over 200 tutorials starting from the most basic of programs, to more advanced and complex logic. 

After creating numerous tutorials and guides on Android Development I have learned that you can never prepare for an error that will arise when trying to make your first Android application. In order to accommodate for this, I have provided you with my email address so that you can email me with your problems.

Please include in the email:
- Your Name
- Tutorial Name
- Your Problem
- Screenshots of your problem

Send To:
jastuder@iastate.edu

When I receive this email, I will try and recreate your problem in order to help you solve it and get back to you within 5 days. Please allow for an additional 2 days before emailing me again with your problem due to my busy schedule at times. 

Comments

SahanA5 (author)2017-11-14

Here some other way for build android calculator......... copy paste and try ...!!

package com.example.deadhot.simplecalculator;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.EditText;import android.widget.Switch;import android.widget.TextView;public class MainActivity extends AppCompatActivity implements View.OnClickListener{ Button b1,b2,b3,b4; TextView tv1; EditText et1,et2; @Overrideprotected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); init(); } private void init() { b1=(Button) findViewById(R.id.button); b2=(Button) findViewById(R.id.button2); b3=(Button) findViewById(R.id.button3); b4=(Button) findViewById(R.id.button4); tv1=(TextView) findViewById(R.id.textView3); et1=(EditText) findViewById(R.id.num1); et2=(EditText) findViewById(R.id.num2); b1.setOnClickListener(this); b2.setOnClickListener(this); b3.setOnClickListener(this); b4.setOnClickListener(this); } @Overridepublic void onClick(View v) { String number1=et1.getText().toString(); String number2=et2.getText().toString(); switch (v.getId()){ case R.id.button : int add=Integer.parseInt(number1)+Integer.parseInt(number2); tv1.setText(String.valueOf(add)); break; case R.id.button2: int sub=Integer.parseInt(number1)-Integer.parseInt(number2); tv1.setText(String.valueOf(sub)); break; case R.id.button3: int multi=Integer.parseInt(number1)*Integer.parseInt(number2); tv1.setText(String.valueOf(multi)); break; case R.id.button4: try { int dev=Integer.parseInt(number1)/Integer.parseInt(number2); tv1.setText(String.valueOf(dev)); break; }catch (Exception e){ tv1.setText("Cannot Do"); } } }}

SaranyaN3 (author)2017-03-06

This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck.

<a href ="http://www.credosystemz.com/training-in-chennai/best-android-training-in-chennai/">Android Training in chennai</a> | <a href ="http://www.credosystemz.com/training-in-chennai/best-android-training-in-chennai/">Android Training </a>

NoumanB1 (author)2016-11-04

code download e nhi ho rha, q?

MatinO (author)2016-10-25

can u find how to build a calculator?

aviD6 made it! (author)2016-09-22

This tutorial is very helpful to get the basics done. Just like avinash I was able to make my own Calculator for play store.

Link : https://goo.gl/oqhLK2

ErwinG9 (author)2016-07-29

Helpful! Thanks.

AvinashB15 made it! (author)2016-03-13

This tutorial was very helpful and I was able to get the basics cleared. I was able to build my own app for Play Store from this. Thank you very much Sir.

App Link: https://goo.gl/oMlqmn

akhileshw1 (author)2016-01-30

it is very nice information but for beginners its difficult beginners ca alse visit

http://infoocode.blogspot.com/2015/11/Simple-android-calculator-code.html

NaumanR1 (author)2015-11-07

very nice information but for beginners its difficult beginners ca alse visit http://infoocode.blogspot.com/2015/11/Simple-android-calculator-code.html

RealynF (author)2015-09-29

nice...

jamilmk made it! (author)2014-11-23

sir i have a problem in creating the android virtual device AVD.

VarunP5 (author)jamilmk2015-09-08

This is because you haven't downloaded any system image for the AVD to run. Open SDK manager and install ARM EABI v7a system image of any version of android. Enjoy

neshkelvin64 (author)2015-06-28

hi sir..need help from u!!!
how to create password in calculator. the method and step to create password to launching application. can u help me.. urgent please.. thank you

AnthonyM16 (author)2015-05-02

Your video is upside down for me?

JyotsnaA (author)2014-12-10

we are going to implement a simple calculator App with basic functionality such as addition, subtraction, multiplication and division.

We need

1. Two EditText to enter our values(operands)

2. One Spinner to choose which operation to perform i.e. Addition, subtraction, Multiplication, Division. (spinner widget is used to implement drop-down list in android)

3. A button which will be clicked to perform the operation.

4. One more EditText widget to show the result

for full solution of the sample refer here:
http://www.mindstick.com/Articles/3b162818-5e3d-4290-8520-ee36886e3a4e/Simple%20Calculator%20App%20in%20Android

КоляП (author)2014-11-23

Hi. I have a problem in some parts of your tutorial.

Eclipse give a lot of errors, ex.:

layout cannot be resolved or is not a field.

How can I solve this problem? Thx

AshwiniR1 (author)2014-10-31

very helpful tutorial. Neat clearly explained Thank you so much :)

Helped me a lot :)

Keep it up

BalaS1 (author)2014-08-03

Best with 55+ Calculators

Play store -> AVL Visionary -> PUBLIC CALCULATOR

https://play.google.com/store/apps/details?id=com.luckyCalculator

MeghnilMJ (author)2014-03-27

m a Beginner for Android Development ri8 nw.
so can i get the some kind of project stuff which will be my project ....
i found it difficult to get the thing for android project

i kindly request you to provide me support and give some project URL's so that i can made it possible i.e android PROJECT for my curriculam

About This Instructable

409,000views

36favorites

License:

More by jastuder:Android Development: Creating a Basic Calculator
Add instructable to: