Step 1: Install android studio and sdk.
Step 2: Open the adroid studio after design the app use this code.
Step 3: Write a java code in this app use to this code.
Java Code:
- package com.example.sreenath.sum1;
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.Menu;
- import android.view.MenuItem;
- import android.view.View;
- import android.widget.*;
- public class MainActivity extends Activity
- {
- EditText txtNum1;
- EditText txtNum2;
- EditText txtTotal;
- Button btnCompute;
- @Override
- public void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- txtNum1 = (EditText) findViewById(R.id.editText1);
- txtNum2 = (EditText) findViewById(R.id.editText2);
- txtTotal = (EditText) findViewById(R.id.editText3);
- btnCompute = (Button) findViewById(R.id.button1);
- btnCompute.setOnClickListener(new ClickButton());
- }
- private class ClickButton implements onClickListener
- {
- public void onClick(View v)
- {
- int x = Integer.parseInt(txtNum1.getText().toString());
- int y = Integer.parseInt(txtNum2.getText().toString());
- int total = x + y;
- txtTotal.setText(Integer.toString(total));
- }
- }
- @Override
- public boolean onCreateOptionsMenu(Menu menu)
- {
- // Inflate the menu; this adds items to the action bar if it is present.
- getMenuInflater().inflate(R.menu.menu_main, menu);
- return true;
- }
- @Override
- public boolean onOptionsItemSelected(MenuItem item)
- {
- // Handle action bar item clicks here. The action bar will
- // automatically handle clicks on the Home/Up button, so long
- // as you specify a parent activity in AndroidManifest.xml.
- int id = item.getItemId();
- //noinspection SimplifiableIfStatement
- if (id == R.id.action_settings)
- {
- return true;
- }
- return super.onOptionsItemSelected(item);
- }
- }
XML Code:
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity" android:id="@+id/sree">
- <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/editText1" android:layout_alignParentTop="true" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginLeft="41dp" android:layout_marginStart="41dp" android:layout_marginTop="94dp" />
- <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/editText2" android:layout_below="@+id/editText1" android:layout_alignLeft="@+id/editText1" android:layout_alignStart="@+id/editText1" android:layout_marginTop="47dp" />
- <EditText android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/editText3" android:layout_below="@+id/editText2" android:layout_alignLeft="@+id/editText2" android:layout_alignStart="@+id/editText2" android:layout_marginTop="65dp" />
- <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="SUM" android:id="@+id/button1" android:layout_below="@+id/editText3" android:layout_centerHorizontal="true" android:layout_marginTop="54dp" />
- </RelativeLayout>
Step 4: Run the application use to emulator.
Step 5: Create a AVD.
Successfully complted the your sum application.Thank you all.
