我有一个名为“光圈”的下拉菜单,其中包含一系列数字,还有一个名为“模式”的下拉菜单,其中有两个选项。当按下按钮时,我需要运行计算,使用各种输入,包括来自“光圈”的当前选择和从“模式”派生的值。如何调用下拉菜单的值,以便我可以在计算中使用它?
此外,在实现计算之前,如何使用“模式”下拉菜单的选择来设置另一个值?具体而言,如果将下拉菜单设置为 Small,则我需要使用0.015进行计算,而如果选择Large,则需要使用0.028。
我的其他输入是EditText视图,因此我现在的设置如下:
此外,在实现计算之前,如何使用“模式”下拉菜单的选择来设置另一个值?具体而言,如果将下拉菜单设置为 Small,则我需要使用0.015进行计算,而如果选择Large,则需要使用0.028。
我的其他输入是EditText视图,因此我现在的设置如下:
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);
}
}
这不是实际的方程式,只是一个测试,以确保一切连接正常。我该如何调用微调器“光圈”的值和小/大微调器“模式”的值?