Wednesday, 24 July 2019

Android Programs(Add two numbers)


import android.widget.*;
import android.view.*;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {
Button b1;
EditText t1,t2,t3;
            @Override
            protected void onCreate(Bundle savedInstanceState) {
                        super.onCreate(savedInstanceState);
                        setContentView(R.layout.activity_main);
                        t1=(EditText) findViewById(R.id.editText1);
                        t2=(EditText) findViewById(R.id.editText2);
                        t3=(EditText) findViewById(R.id.editText3);
                        b1=(Button) findViewById(R.id.button1);
                        b1.setOnClickListener(s1);
            }
public OnClickListener s1=new OnClickListener()
{
   public void onClick(View v){
               if(v==b1){
               int a=Integer.parseInt(t1.getText().toString());
               int b=Integer.parseInt(t2.getText().toString());
               int c=a+b;
               t3.setText(String.valueOf(c));
 Toast.makeText(getApplicationContext(),String.valueOf(c), Toast.LENGTH_SHORT).show();
               }
   }
};
}

No comments:

Post a Comment