1) src\ app.hitesh\ AddTwoNumberApp2Activity.java
package app.hitesh;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class AddTwoNumberApp2Activity extends Activity implements OnClickListener {
Button btnrel;
EditText txtval1,txtval2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnrel=(Button)findViewById(R.id.btnsum);
txtval1=(EditText)findViewById(R.id.txtval1);
txtval2=(EditText)findViewById(R.id.txtval2);
btnrel.setOnClickListener(this);
}
public void onClick(View v) {
int value1=Integer.parseInt(txtval1.getText().toString());
int value2=Integer.parseInt(txtval2.getText().toString());
int rel=value1+value2;
Toast.makeText(this, String.valueOf(rel), Toast.LENGTH_SHORT).show();
}
}
2) res\ layout\ main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.06" android:gravity="center" android:text="Addition of Two Number" android:textSize="17dp"/>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.06" android:hint="First Value" android:id="@+id/txtval1">
<requestFocus></requestFocus>
</EditText>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.06" android:hint="Second Value" android:id="@+id/txtval2"></EditText>
<Button android:layout_height="wrap_content" android:layout_weight="0.06" android:layout_width="103dp" android:text="Addition" android:id="@+id/btnsum"></Button>
<TextView
android:id="@+id/textView1"
android:layout_width="305dp"
android:layout_height="wrap_content"
android:layout_weight="0.06"
android:text="Hitesh Jadav"
android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#708090"/>
</LinearLayout>
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
public class AddTwoNumberApp2Activity extends Activity implements OnClickListener {
Button btnrel;
EditText txtval1,txtval2;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btnrel=(Button)findViewById(R.id.btnsum);
txtval1=(EditText)findViewById(R.id.txtval1);
txtval2=(EditText)findViewById(R.id.txtval2);
btnrel.setOnClickListener(this);
}
public void onClick(View v) {
int value1=Integer.parseInt(txtval1.getText().toString());
int value2=Integer.parseInt(txtval2.getText().toString());
int rel=value1+value2;
Toast.makeText(this, String.valueOf(rel), Toast.LENGTH_SHORT).show();
}
}
2) res\ layout\ main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:weightSum="1">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="0.06" android:gravity="center" android:text="Addition of Two Number" android:textSize="17dp"/>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.06" android:hint="First Value" android:id="@+id/txtval1">
<requestFocus></requestFocus>
</EditText>
<EditText android:layout_height="wrap_content" android:layout_width="fill_parent" android:layout_weight="0.06" android:hint="Second Value" android:id="@+id/txtval2"></EditText>
<Button android:layout_height="wrap_content" android:layout_weight="0.06" android:layout_width="103dp" android:text="Addition" android:id="@+id/btnsum"></Button>
<TextView
android:id="@+id/textView1"
android:layout_width="305dp"
android:layout_height="wrap_content"
android:layout_weight="0.06"
android:text="Hitesh Jadav"
android:textAppearance="?android:attr/textAppearanceLarge" android:textColor="#708090"/>
</LinearLayout>
![]() |
| Add Two Number |

Thank you for the code that you've shared. It helps a lot.
ReplyDeleteHope that you will tired of posting solutions.
Godbless you always.
Stundent from Philippines.
setContentView(R.layout.main);
ReplyDeletegetting error in main
This comment has been removed by the author.
ReplyDeleteThis comment has been removed by the author.
ReplyDeleteThere are too much illogical syntaxes in this language, Android. For example; there is already find by ID command and defined objects in the xml file. Then why plus write (control name) before the line¿ Two; that int value assignment. If there is an 'int' definition for a value then why need to write 'integer' and 'parseInt' definitions-functions¿ Writing more code is not seem to be clever, unnecessary hardness.
ReplyDeletesetContentView(R.layout.main);
ReplyDeletegetting error in main
Existing without the answers to the difficulties you’ve sorted out through this guide is a critical case, as well as the kind which could have badly affected my entire career if I had not discovered your website.
ReplyDeleteDigital Marketing online training
full stack developer training in pune
full stack developer training in annanagar
full stack developer training in tambaram
full stack developer training in velachery
I am really happy with your blog because your article is very unique and powerful for new reader.
ReplyDeleteClick here:
Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium online Training
if we use only one edit text and sum display in textview on button click please comment of this problem.
ReplyDelete
ReplyDeleteThanks for sharing the knowledgeable stuff to enlighten us no words for this amazing blog.. learnt so many things I recommend everyone to learn something from this blogger and blog.. I am sharing it with others also
IT Software Training in Chennai | Python Training in Chennai | Dot Net Training in Chennai |Android Training in Chennai | J2ee Training in Chennai
An outstanding share! I have just forwarded this onto a colleague who had been doing a little research on this. And he actually bought me dinner because I found it for him... lol. So let me reword this.... Thank YOU for the meal!! But yeah, thanks for spending time to talk about this matter here on your blog.
ReplyDeletewow rally this coding awesome.. really useful to me because i love coding amazing information sharing to all thanks for your valuable information thanks lot!!!
ReplyDeleteAndroid Training Institute in Chennai | Certification | Online Course Training | Android Training Institute in Bangalore | Certification | Online Course Training | Android Training Institute in Hyderabad | Certification | Online Course Training | Android Training Institute in Coimbatore | Certification | Online Course Training | Android Training Institute in Online | Certification | Online Course Training
I must appreciate you for providing such a valuable content for us. This is one amazing piece of article. Helped a lot in increasing my knowledge
ReplyDeletesap training in chennai
sap training in porur
azure training in chennai
azure training in porur
cyber security course in chennai
cyber security course in porur
ethical hacking course in chennai
ethical hacking course in porur