Mekillerow Mekillerow - 2 months ago 5
Android Question

Add a value 0 to a variable if EditText is empty

Here's the code I'm using:

EditText ii1 = (EditText)findViewById(R.id.i1);
String iii1= (String)ii1.getText().toString();
ind1=Double.parseDouble(iii1);


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

Thanks!

UPDATE:

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


Thank you all for the help!

Answer

You sould compare strings with

iii1.equals("")

instead of iii1 = ""

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

Comments