Mekillerow Mekillerow - 1 year ago 64
Android Question

Add a value 0 to a variable if EditText is empty

Here's the code I'm using:

EditText ii1 = (EditText)findViewById(;
String iii1= (String)ii1.getText().toString();

I need that ind1 acquire value 0 if the EditText is empty.
I already tried using
if (ii1 = "")
if (iii1= "")
, but didn't work. How can I do that??



Got it using this code:
if (iii1.equals("")) {ind1=0;} else {ind1 = Double.parseDouble(iii1);}

Thank you all for the help!

Answer Source

You sould compare strings with


instead of iii1 = ""

And please, names like "iii1" are suicide sooner or later...

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download