Note that there are some explanatory texts on larger screens.

plurals
  1. POhow can set edit text as output and input?
    primarykey
    data
    text
    <p>I'd like to know how to have multiple <em>EditText</em>, detect if one of those were modified and calculate the value to set txt of the not modified <em>EditText</em> in relation with the other.<br> It should be like a formula solver: 4 <em>EditText</em> 1 <em>Button</em>.</p> <p>When you press the button if one of the <em>EditText</em> is empty the text of the empty one has to be set to a value obtained with the value of the others. Actually it seems not to work, the activity crush when I press the calculate button. </p> <pre><code>public class motolineare extends Activity implements OnClickListener { EditText et1; EditText et2; EditText et3; EditText et4; Button calculate; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.formula); TextView textView1 = (TextView) findViewById(R.id.textView1); textView1.setGravity(Gravity.CENTER_HORIZONTAL); et1 = (EditText) findViewById(R.id.et1); et2 = (EditText) findViewById(R.id.et2); et3 = (EditText) findViewById(R.id.et3); et4 = (EditText) findViewById(R.id.et4); calculate = (Button) findViewById(R.id.calculate); calculate.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub double num1 = 0; double num2 = 0; double num3 = 0; double num4 = 0; double res = 0; if ((TextUtils.isEmpty(et1.getText().toString()) &amp; TextUtils .isEmpty(et2.getText().toString())) || ((TextUtils.isEmpty(et1.getText().toString()) &amp; TextUtils .isEmpty(et3.getText().toString()))) || ((TextUtils.isEmpty(et1.getText().toString()) &amp; TextUtils .isEmpty(et4.getText().toString()))) || ((TextUtils.isEmpty(et2.getText().toString()) &amp; TextUtils .isEmpty(et3.getText().toString()))) || ((TextUtils.isEmpty(et2.getText().toString()) &amp; TextUtils .isEmpty(et4.getText().toString()))) || ((TextUtils.isEmpty(et4.getText().toString()) &amp; TextUtils .isEmpty(et3.getText().toString())))) { return; } num1 = Double.parseDouble(et1.getText().toString()); num2 = Double.parseDouble(et2.getText().toString()); num3 = Double.parseDouble(et3.getText().toString()); num4 = Double.parseDouble(et4.getText().toString()); switch (v.getId()) { case R.id.calculate: if ((TextUtils.isEmpty(et1.getText().toString()))) { res = (num2 * num3) / num4; editText.setText(" " + res); } else if ((TextUtils.isEmpty(et2.getText().toString()))) { res = (num1 * num4) / num3; EditText editText = (EditText) findViewById(R.id.et2); editText.setText(" " + res); } else if ((TextUtils.isEmpty(et3.getText().toString()))) { res = (num4 * num1) / num2; EditText editText = (EditText) findViewById(R.id.et3); editText.setText(" " + res); } else if ((TextUtils.isEmpty(et4.getText().toString()))) { res = (num2 * num3) / num1; EditText editText = (EditText) findViewById(R.id.et4); editText.setText(" " + res); } break; default: break; } } } </code></pre> <p>Logcat output:</p> <pre> 11-11 19:05:22.130: E/AndroidRuntime(1911): FATAL EXCEPTION: main 11-11 19:05:22.130: E/AndroidRuntime(1911): java.lang.NumberFormatException: Invalid double: "" 11-11 19:05:22.130: E/AndroidRuntime(1911): at java.lang.StringToReal.invalidReal(StringToReal.java:63) 11-11 19:05:22.130: E/AndroidRuntime(1911): at java.lang.StringToReal.parseDouble(StringToReal.java:248) 11-11 19:05:22.130: E/AndroidRuntime(1911): at java.lang.Double.parseDouble(Double.java:295) 11-11 19:05:22.130: E/AndroidRuntime(1911): at com.example.easyphysics.motolineare.onClick(motolineare.java:73) 11-11 19:05:22.130: E/AndroidRuntime(1911): at android.view.View.performClick(View.java:4084) 11-11 19:05:22.130: E/AndroidRuntime(1911): at android.view.View$PerformClick.run(View.java:16966) 11-11 19:05:22.130: E/AndroidRuntime(1911): at android.os.Handler.handleCallback(Handler.java:615) 11-11 19:05:22.130: E/AndroidRuntime(1911): at android.os.Handler.dispatchMessage(Handler.java:92) 11-11 19:05:22.130: E/AndroidRuntime(1911): at android.os.Looper.loop(Looper.java:137) 11-11 19:05:22.130: E/AndroidRuntime(1911): at android.app.ActivityThread.main(ActivityThread.java:4745) 11-11 19:05:22.130: E/AndroidRuntime(1911): at java.lang.reflect.Method.invokeNative(Native Method) 11-11 19:05:22.130: E/AndroidRuntime(1911): at java.lang.reflect.Method.invoke(Method.java:511) 11-11 19:05:22.130: E/AndroidRuntime(1911): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786) 11-11 19:05:22.130: E/AndroidRuntime(1911): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553) 11-11 19:05:22.130: E/AndroidRuntime(1911): at dalvik.system.NativeStart.main(Native Method) 11-11 19:05:25.371: E/Trace(1932): error opening trace file: No such file or directory (2) </pre>
    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.
 

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