How to do develop mini calculator application in android studio tool? Easily make android app.

JAVA Source Code:

MainActivity.java

package com.example.minicalculator;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {
    EditText tv1,tv2,tv3;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        tv1=findViewById(R.id.t1);
        tv2=findViewById(R.id.t2);
        tv3=findViewById(R.id.t3);
    }
    public void add(View v)
    {
        int a=Integer.parseInt(tv1.getText().toString());
        int b=Integer.parseInt(tv2.getText().toString());
        int result=a+b;
        tv3.setText(String.valueOf(result));
    }
    public void sub(View v)
    {
        int a=Integer.parseInt(tv1.getText().toString());
        int b=Integer.parseInt(tv2.getText().toString());
        int result=a-b;
        tv3.setText(String.valueOf(result));
    }
    public void mul(View v)
    {
        int a=Integer.parseInt(tv1.getText().toString());
        int b=Integer.parseInt(tv2.getText().toString());
        int result=a*b;
        tv3.setText(String.valueOf(result));
    }
}

XML Source Code:

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_height="match_parent"
    android:layout_width="match_parent"
    android:stretchColumns="*">
    <TableRow>
        <EditText android:width="220dp" android:hint="Enter the First number" android:id="@+id/t1" />
    </TableRow>
    <TableRow>
        <EditText android:width="220dp" android:hint="Enter the Second number" android:id="@+id/t2" />
    </TableRow>
    <TableRow>
        <EditText android:width="220dp" android:hint="Result" android:id="@+id/t3" />
    </TableRow>
    <TableRow>
        <Button android:text="Addition" android:width="100dp" android:onClick="add"/>
    </TableRow>
    <TableRow>
        <Button android:text="Subtraction" android:width="100dp" android:onClick="sub"/>
    </TableRow>
    <TableRow>
        <Button android:text="Multiplication" android:width="100dp" android:onClick="mul"/>
    </TableRow>
</TableLayout>

AndroidManifest(File):

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.minicalculator">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

Click on below link:

https://youtu.be/aYNRqAXxhaQ

Android Studio Tool Download link given below:

https://developer.android.com/studio

Channel link:

https://www.youtube.com/channel/UCX1KgUr3ZA6cCR81qGGpA6g?sub_confirmation=1

Leave a Reply

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