document.write('
Data hosted with ♥ by Pastebin.com - Download Raw - See Original
  1. package project.radiobutton;
  2.  
  3. import android.app.Activity;
  4. import android.os.Bundle;
  5. import android.view.View;
  6. import android.widget.EditText;
  7. import android.widget.RadioButton;
  8. import android.widget.TextView;
  9.  
  10. public class RadiobuttonprojectActivity extends Activity {
  11.    
  12.     private EditText et1,et2;
  13.     private TextView tv3;
  14.     private RadioButton r1,r2;
  15.    
  16.     /** Called when the activity is first created. */
  17.     @Override
  18.     public void onCreate(Bundle savedInstanceState) {
  19.         super.onCreate(savedInstanceState);
  20.         setContentView(R.layout.main);
  21.  
  22.         et1=(EditText)findViewById(R.id.et1);
  23.         et2=(EditText)findViewById(R.id.et2);
  24.         tv3=(TextView)findViewById(R.id.tv3);
  25.         r1=(RadioButton)findViewById(R.id.r1);
  26.         r2=(RadioButton)findViewById(R.id.r2);
  27.     }
  28.    
  29.   //Este método se ejecutará cuando se presione el botón
  30.     public void operar(View view) {
  31.         String valor1=et1.getText().toString();
  32.         String valor2=et2.getText().toString();
  33.         int nro1=Integer.parseInt(valor1);
  34.         int nro2=Integer.parseInt(valor2);
  35.         if (r1.isChecked()==true) {
  36.             int suma=nro1+nro2;
  37.             String resu=String.valueOf(suma);
  38.             tv3.setText(resu);
  39.         } else
  40.             if (r2.isChecked()==true) {
  41.                 int resta=nro1-nro2;
  42.                 String resu=String.valueOf(resta);
  43.                 tv3.setText(resu);                
  44.             }
  45.     }    
  46.    
  47. }
');