Do String
comparison using equals
.
spinner.getItemAtPosition(pos).toString()=="first"
instead use:
spinner.getItemAtPosition(pos).toString().equals("first")
Similarly for:
s2.getItemAtPosition(id).toString()=="second"
instead use:
s2.getItemAtPosition(id).toString().equals("second")
Read this for more information.
==
compares references,not the values. In your case, you want to check for the value equality, not the reference equality.
EDIT:
Since you have mentioned that your code is generating NumberFormatException
, I probably believe that either pos
or id
are of String
type generating the NumberFormatException
.
EDIT 2:
As per the your comment:
float x=Float.parseFloat(String.valueOf(et.getText()));
Your getText()
is returning a String
that can't be actually parsed into a float
. Try checking if the content is actually a float
in String
format.
Besides, use String.trim()
before parsing to ensure your String
doesn't contain any leading or trailing whitespaces that's generating the NumberFormatException
.