0% found this document useful (0 votes)
39 views2 pages

Addition

The document contains code for an Android application layout and Java code to perform addition. The layout defines EditText fields for two numbers and a result, and a button to trigger addition. The Java code finds the EditText views, parses the number strings to doubles, calculates the sum, and sets the result EditText text.

Uploaded by

Safa M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views2 pages

Addition

The document contains code for an Android application layout and Java code to perform addition. The layout defines EditText fields for two numbers and a result, and a button to trigger addition. The Java code finds the EditText views, parses the number strings to doubles, calculates the sum, and sets the result EditText text.

Uploaded by

Safa M
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

<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:paddingBottom="50dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="10dp"
tools:context="com.infotech.safa.myapplication1.MainActivity" >

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginTop="37dp"
android:text="First Number"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/txtB"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView2"
android:layout_below="@+id/textView2"
android:ems="10"
android:inputType="numberDecimal" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtA"
android:layout_below="@+id/txtA"
android:layout_marginTop="15dp"
android:text="Second Number"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/txtA"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView1"
android:layout_below="@+id/textView1"
android:ems="10"
android:inputType="numberDecimal" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/txtB"
android:layout_below="@+id/txtB"
android:layout_marginTop="28dp"
android:text="Result"
android:textAppearance="?android:attr/textAppearanceLarge" />

<EditText
android:id="@+id/txtRes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/textView3"
android:layout_below="@+id/textView3"
android:ems="10"
android:inputType="numberDecimal" >

<requestFocus />
</EditText>
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txtRes"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:onClick="onClk"
android:text="Addition" />

</RelativeLayout>

package com.infotech.safa.myapplication1;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;

public class MainActivity extends AppCompatActivity {


EditText txt1,txt2,txt3;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

txt1=(EditText) findViewById(R.id.txtA);
txt2=(EditText) findViewById(R.id.txtB);
txt3=(EditText) findViewById(R.id.txtRes);

public void onClk(View v){


double a,b,c;
a=Double.parseDouble(txt1.getText().toString());
b=Double.parseDouble(txt2.getText().toString());
c=a+b;
txt3.setText(String.valueOf(c));
}

You might also like