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));
}
}
}