Developing your first android app – Simple calculator

First Android App - androidhunger.com

Hello everyone, welcome to Android Hunger. Here I am going to tell you ‘How to create your first android app !

This is a simple app which takes two numbers and perform arithmetic operations like addition, subtraction, multiplication, and division on them.

Project on Github Download the app

  • Here I made two simple EditText with a TextView for each of them.
  • 4 Buttons for each operation (addition, subtraction, multiplication and division)
  • A TextView for displaying a result.
First Android App - androidhunger.com

First Android App – androidhunger.com

 

In the previous post, I discussed on different UI layouts in android, here I used  LinearLayout for designing the above screen, also nested some LinearLayouts with horizontal and vertical orientation for achieving it.

Below is the component tree of the view,

First Android App - androidhunger.com

First Android App – androidhunger.com

Project on Github Download the app

First, we design the layout of the app, here we use XML to do it,
The code for activity_main.xml,

The functionality part is generally written in java,

In the MainActivity I initialize the widgets used like Button, TextViews, and EditTexts.

Now when these buttons are clicked a specific operation is performed, so I set OnClickListener to them.

When ‘+’ button is clicked:

When ‘-‘ button is clicked:

When ‘*’ button is clicked:

When ‘/’ button is clicked:

Hope you you created your first android application by following this tutorial. Also please feel free to take a look at some of the other tutorials here.

Project on Github Download the app

Leave a Reply

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