Introduction

Ninety percent of people use Android smartphones. I will show you how to create an addition application for Android using Android studio. Android is a kernel based operating system. It allows the user to modify the GUI components and source code.
Requirements
Download link (android studio) https://developer.android.com/studio/

Steps should be followed

Carefully follow my steps on how to create the addition application for android using android studio and I have included the source code below.
Step 1
Open Android studio start the new project.
Android studio
Step 2
Put the application name and company domain. If you wish to use c++ for code the project, Include c++ support then click next.
Android studio
Step 3
Select the android minimum SDK. After you chose the minimum SDK it will show approximate percentage of people who use that sdk then click next.
android minimum SDK
Step 4
Choose the basic activity then click next
Add an Activity to Mobile
Step 5
Put the activity name and layout name. Android studio basically takes the java class name from what you provide as the activity name.
Customize the Activity
Step 6
Goto activity_layout.xml then click the text bottom. Into the activity_layout.xml copy and paste the below code.
activity_layout.xml code
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
  2. android:id="@+id/relativeLayout1"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent" >
  5. <LinearLayout
  6. android:id="@+id/linearLayout1"
  7. android:layout_width="wrap_content"
  8. android:layout_height="wrap_content"
  9. android:layout_alignParentLeft="true"
  10. android:layout_alignParentRight="true"
  11. android:layout_alignParentTop="true" >
  12. <TextView
  13. android:layout_width="wrap_content"
  14. android:layout_height="wrap_content"
  15. android:layout_gravity="center"
  16. android:text="ADDITION"
  17. android:textSize="20dp" >
  18. </TextView>
  19. </LinearLayout>
  20. <LinearLayout
  21. android:id="@+id/linearLayout2"
  22. android:layout_width="wrap_content"
  23. android:layout_height="wrap_content"
  24. android:layout_alignParentLeft="true"
  25. android:layout_alignParentRight="true"
  26. android:layout_below="@+id/linearLayout1" >
  27. <TextView
  28. android:layout_width="wrap_content"
  29. android:layout_height="wrap_content"
  30. android:text="ENTER NO 1" >
  31. </TextView>
  32. <EditText
  33. android:layout_width="wrap_content"
  34. android:layout_height="wrap_content"
  35. android:layout_weight="0.20"
  36. android:id="@+id/edittext1"
  37. android:inputType="number">
  38. </EditText>
  39. </LinearLayout>
  40. <LinearLayout
  41. android:id="@+id/linearLayout3"
  42. android:layout_width="wrap_content"
  43. android:layout_height="wrap_content"
  44. android:layout_alignParentLeft="true"
  45. android:layout_alignParentRight="true"
  46. android:layout_below="@+id/linearLayout2" >
  47. <TextView
  48. android:layout_width="wrap_content"
  49. android:layout_height="wrap_content"
  50. android:text="ENTER NO 2" >
  51. </TextView>
  52. <EditText
  53. android:layout_width="wrap_content"
  54. android:layout_height="wrap_content"
  55. android:layout_weight="0.20"
  56. android:id="@+id/edittext2"
  57. android:inputType="number">
  58. </EditText>
  59. </LinearLayout>
  60. <LinearLayout
  61. android:id="@+id/linearLayout4"
  62. android:layout_width="wrap_content"
  63. android:layout_height="wrap_content"
  64. android:layout_alignParentLeft="true"
  65. android:layout_alignParentRight="true"
  66. android:layout_below="@+id/linearLayout3" >
  67. <Button
  68. android:layout_width="wrap_content"
  69. android:id="@+id/button1"
  70. android:layout_height="wrap_content"
  71. android:text="Addition"
  72. android:layout_weight="0.50" />
  73. <Button
  74. android:layout_width="wrap_content"
  75. android:id="@+id/button3"
  76. android:layout_height="wrap_content"
  77. android:text="subtraction"
  78. android:layout_weight="0.50" />
  79. <Button
  80. android:layout_width="wrap_content"
  81. android:id="@+id/button2"
  82. android:layout_height="wrap_content"
  83. android:text="CLEAR"
  84. android:layout_weight="0.50" />
  85. </LinearLayout>
  86. <View
  87. android:layout_height="2px"
  88. android:layout_width="fill_parent"
  89. android:layout_below="@+id/linearLayout4"
  90. android:background="#DDFFDD"/>
  91. </RelativeLayout>
Android studio
Step 7
This is our user interface of the application
Android studio user interface
Step 8
Go to LayoutActivity.java then click the text bottom. Into the LayoutActivity.java copy and paste the below code. Do not replace your package name.
LayoutActivity.java code
  1. package ganeshannt.layout;
  2. import android.app.Activity;
  3. import android.os.Bundle;
  4. import android.view.View;
  5. import android.view.View.OnClickListener;
  6. import android.widget.Button;
  7. import android.widget.EditText;
  8. import android.widget.Toast;
  9. public class LayoutActivity extends Activity {
  10. /** Called when the activity is first created. */
  11. EditText txtData1,txtData2;
  12. float num1,num2,result1,result2;
  13. @Override
  14. public void onCreate(Bundle savedInstanceState)
  15. {
  16. super.onCreate(savedInstanceState);
  17. setContentView(R.layout.activity_layout);
  18. Button add = (Button) findViewById(R.id.button1);
  19. add.setOnClickListener(new OnClickListener()
  20. {
  21. public void onClick(View v)
  22. {
  23. try
  24. {
  25. txtData1 = (EditText) findViewById(R.id.edittext1);
  26. txtData2 = (EditText) findViewById(R.id.edittext2);
  27. num1 = Float.parseFloat(txtData1.getText().toString());
  28. num2 = Float.parseFloat(txtData2.getText().toString());
  29. result1=num1+num2;
  30. Toast.makeText(getBaseContext(),"ANSWER:"+result1,Toast.LENGTH_SHORT).show();
  31. }
  32. catch(Exception e)
  33. {
  34. Toast.makeText(getBaseContext(), e.getMessage(),
  35. Toast.LENGTH_SHORT).show();
  36. }
  37. }
  38. });
  39. Button sub = (Button) findViewById(R.id.button3);
  40. sub.setOnClickListener(new OnClickListener()
  41. {
  42. public void onClick(View v)
  43. {
  44. try
  45. {
  46. txtData1 = (EditText) findViewById(R.id.edittext1);
  47. txtData2 = (EditText) findViewById(R.id.edittext2);
  48. num1 = Float.parseFloat(txtData1.getText().toString());
  49. num2 = Float.parseFloat(txtData2.getText().toString());
  50. result2=num1-num2;
  51. Toast.makeText(getBaseContext(),"ANSWER:"+result2,Toast.LENGTH_SHORT).show();
  52. }
  53. catch(Exception e)
  54. {
  55. Toast.makeText(getBaseContext(), e.getMessage(),
  56. Toast.LENGTH_SHORT).show();
  57. }
  58. }
  59. });
  60. Button clear = (Button) findViewById(R.id.button2);
  61. clear.setOnClickListener(new OnClickListener()
  62. {
  63. public void onClick(View v)
  64. {
  65. try
  66. {
  67. txtData1.setText("");
  68. txtData2.setText("");
  69. }
  70. catch(Exception e)
  71. {
  72. Toast.makeText(getBaseContext(), e.getMessage(),
  73. Toast.LENGTH_SHORT).show();
  74. }
  75. }
  76. });
  77. }
  78. }
Android studio
Step 9
Click the build bottom and make the project. Now your project compilation process is going on. It will show you any error found in your project
Android project build
Step 10
Click run bottom. Your emulator will start then run your application.
Android emulator
Deliverables
Here we have successfully created addition application for android using android studio
Android addition application
Android addition application
Don’t forgot to like and follow me. If you have any doubts just comment below.