Website Visitor

Add Two Number Source code

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>




Add Two Number

13 comments:

  1. Thank you for the code that you've shared. It helps a lot.
    Hope that you will tired of posting solutions.

    Godbless you always.

    Stundent from Philippines.

    ReplyDelete
  2. setContentView(R.layout.main);
    getting error in main

    ReplyDelete
  3. This comment has been removed by the author.

    ReplyDelete
  4. This comment has been removed by the author.

    ReplyDelete
  5. There 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.

    ReplyDelete
  6. setContentView(R.layout.main);
    getting error in main

    ReplyDelete
  7. 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.
    Digital 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

    ReplyDelete
  8. I am really happy with your blog because your article is very unique and powerful for new reader.
    Click here:
    Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium online Training

    ReplyDelete
  9. if we use only one edit text and sum display in textview on button click please comment of this problem.

    ReplyDelete

  10. Thanks 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

    ReplyDelete
  11. 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.

    ReplyDelete