Dividing Values In Spinners - Android
I am trying to get the values from spinner 1 and divide it with the value from spinner 2 and then multiply with the current amount. This is the code i have but it gives me a force
Solution 1:
Are you getting the value of the Spinner
and assigning it to spinner1
and spinner2
somewhere in the code that you have not posted?
If you are not then that is where the problem is. You can't get the Spinner
's value by just calling spinner1.toString()
or spinner2.toString()
.
To get the value of the spinner
use...
spinner.getSelectedItem().toString();
So in your case...
double result2 = Double.valueOf(spinner1.getSelectedItem().toString()) / Double.valueOf(spinner2.getSelectedItem().toString());
Solution 2:
I think this is the bug:
double result2 = Double.valueOf(spinner1.toString()) / Double.valueOf(spinner2.toString());
Change it to:
double result2 = Double.valueOf(spinner1.getSelectedItem().toString()) / Double.valueOf(spinner2.getSelectedItem().toString());
Post a Comment for "Dividing Values In Spinners - Android"