 <p>Full disclosure: From my personal blog</p> <p><a href="http://stackentry.blogspot.in/2016/01/addition-of-two-numbers-in-android.html" rel="nofollow">Addition program in android</a></p> <p>XML and Java code for addition of two numbers in android</p> <p>Mainactivity.java</p> <pre><code>public class MainActivity extends AppCompatActivity implements View.OnClickListener{ private EditText editText,editText2,editText4; int v1,v2,v3; String s="ans"; private Button button; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); button=(Button)findViewById(R.id.button); button.setOnClickListener(this); } @Override public void onClick(View v) { editText=(EditText)findViewById(R.id.editText); editText2=(EditText)findViewById(R.id.editText2); editText4=(EditText)findViewById(R.id.editText4); v1=Integer.parseInt(editText.getText().toString()); v2=Integer.parseInt(editText2.getText().toString()); v3=v1+v2; s=String.valueOf(v3); editText4.setText(s); } @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); } </code></pre> <p>activitymain.xml </p> <pre><code> &lt;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"&gt; &lt;EditText android:layout_width="500dp" android:layout_height="40dp" android:id="@+id/editText2" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_marginTop="60dp" /&gt; &lt;EditText android:layout_width="500dp" android:layout_height="40dp" android:id="@+id/editText" android:layout_alignParentLeft="true" android:layout_alignParentStart="true" android:layout_below="@+id/editText2" /&gt; &lt;EditText android:layout_width="800dp" android:layout_height="40dp" android:id="@+id/editText4" android:layout_alignParentRight="true" android:layout_alignParentEnd="true" android:layout_below="@+id/editText" /&gt; &lt;Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="OK" android:id="@+id/button" android:layout_alignParentBottom="true" android:layout_centerHorizontal="true" /&gt; &lt;/RelativeLayout&gt; </code></pre>