Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>try this ... calculation on click as well as on radio button checked change </p> <pre><code>public class MainActivity extends Activity implements OnClickListener, OnCheckedChangeListener { private EditText txt1; private EditText txt2; // private String input1; // private String input2; private Double Num1; private Double Num2; // private String flag; private TextView TextResult; Double Result = 0.0; RadioButton radio0, radio1, radio2, radio3; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.test); findViewById(R.id.button1).setOnClickListener(this); radio0 = (RadioButton) findViewById(R.id.radio0); radio0.setOnCheckedChangeListener(this); radio1 = (RadioButton) findViewById(R.id.radio1); radio1.setOnCheckedChangeListener(this); radio2 = (RadioButton) findViewById(R.id.radio2); radio2.setOnCheckedChangeListener(this); radio3 = (RadioButton) findViewById(R.id.radio3); radio3.setOnCheckedChangeListener(this); TextResult = (TextView) findViewById(R.id.textView2); TextResult.setText("0"); txt1 = (EditText) findViewById(R.id.editText1); txt2 = (EditText) findViewById(R.id.editText2); } public void onradioButtonClicked(View view) { } @Override public void onClick(View v) { getCalculationValue(); // input1 = txt1.getText().toString(); // input2 = txt2.getText().toString(); } @Override public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { getCalculationValue(); } private void getCalculationValue() { Num1 = Double.parseDouble(txt1.getText().toString().trim()); Num2 = Double.parseDouble(txt2.getText().toString().trim()); if (radio0.isChecked()) Result = Num1 + Num2; else if (radio1.isChecked()) Result = Num1 - Num2; else if (radio2.isChecked()) Result = Num1 * Num2; else if (radio3.isChecked()) Result = Num1 / Num2; TextResult.setText(String.valueOf(Result)); } </code></pre> <p>}</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload