0% found this document useful (0 votes)
18 views4 pages

Addition

The document contains an XML layout file for an Android application with a vertical LinearLayout that includes two TextViews for input labels, two EditTexts for number inputs, and a Button for performing addition. The accompanying Java file defines a MainActivity class that handles user input, performs the addition of the two numbers, and displays the result in a third EditText. The application is designed to take two numbers from the user and output their sum when the button is clicked.

Uploaded by

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

Addition

The document contains an XML layout file for an Android application with a vertical LinearLayout that includes two TextViews for input labels, two EditTexts for number inputs, and a Button for performing addition. The accompanying Java file defines a MainActivity class that handles user input, performs the addition of the two numbers, and displays the result in a third EditText. The application is designed to take two numbers from the user and output their sum when the button is clicked.

Uploaded by

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

Myfile.

xml

<?xml version="1.0" encoding="utf-8"?>


<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/an
droid"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/l1"
android:text="NUMBER1"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/t1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/l2"
android:text="NUMBER2"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/t2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/l3"
android:text="ANSWER"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/t3" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/b1"
android:text="ADDITION"
android:onClick="show"/>

</LinearLayout>
Java file

import androidx.appcompat.app.AppCompatActivity;

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

public class MainActivity extends AppCompatActivity


implements View.OnClickListener
{
EditText t1,t2,t3;
Button b1;

protected void onCreate(Bundle b) {


super.onCreate(savedInstanceState);
setContentView(R.layout.myfile);
t1=(EditText) findViewById(R.id.t1);
t2=(EditText) findViewById(R.id.t2);
t3=(EditText) findViewById(R.id.t3);
b1=(Button) findViewById(R.id.b1);
b1.setOnClickListener(this);
}
public void onClick(View v) {
String s1=t1.getText().toString();
String s2=t2.getText().toString();
int n1=Integer.parseInt(s1);
int n2=Integer.parseInt(s2);
int n3=n1+n2;
t3.setText(Integer.toString(n3));

}
}
}

You might also like