I have a spinner 'aperture' set up with a list of numbers, and a spinner 'mode' with two options. When a button is pushed I need a calculation to run using various inputs, including the current selection from 'aperture' and a value derived from 'mode'. How do I call the value of a spinner so I can use it in a calculation?
Also, how do I use the spinner 'mode's selection to set this other value before implimenting it in the calculation? To be more specific, if the spinner is set to Small then the value I use in the calculation is 0.015, whereas if Large is selected I need to use 0.028
My other inputs are EditText views, so right now I am set up like this:
input = (EditText) findViewById(R.id.input1);
input2 = (EditText) findViewById(R.id.input2);
input3 = (EditText) findViewById(R.id.input3);
input4 = (EditText) findViewById(R.id.input4);
output = (TextView) findViewById(R.id.result);
output2 = (TextView) findViewById(R.id.result2);
//aperture dropdown
Spinner s = (Spinner) findViewById(R.id.apt);
ArrayAdapter adapter2 = ArrayAdapter.createFromResource( this, R.array.apertures,
android.R.layout.simple_spinner_item);
adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
s.setAdapter(adapter2);
//button
final Button button = (Button) findViewById(R.id.calculate);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Perform action on click
doCalculation();
}
});
}
private void doCalculation() {
// Get entered input value
String strValue = input.getText().toString();
String strValue2 = input2.getText().toString();
String strValue3 = input3.getText().toString();
String strValue4 = input4.getText().toString();
// Perform a hard-coded calculation
double imperial1 = (Double.parseDouble(strValue3) + (Double.parseDouble(strValue4) / 12));
double number = Integer.parseInt(strValue) * 2;
double number2 = ((number / 20) + 3) / Integer.parseInt(strValue2);
// Update the UI with the result
output.setText("Result: "+ number);
output2.setText("Result2: "+ imperial1);
}
}
That is not the actual equation, it is just a test to make sure everything connects properly. How would I call the value of spinner 'aperture' and the Small/Large spinner 'mode'