我正在创建一个转换计算器,其中有12个按钮(是计算器),每个按钮都将我带到另一个活动。在该活动中,我遇到一个有关如何在微调器和键盘按钮上执行switch语句的问题。我已经尽力了,它也正在工作,但是我不知道它是否正确。
switch (v.getId()) {
case R.id.Button14Keypad1:
// Table Spoon to Tea Spoon
if (spinnerFromOne.equals("Table Spoon(tbsp)") && spinnerToOne.equals("Tea Spoon(tsp)")) {
textview3ToConvert.setText("" + tspOne);
}
// Table Spoon to Ounces
if (spinnerFromOne.equals("Table Spoon(tbsp)") && spinnerToOne.equals("Ounces(oz)")) {
textview3ToConvert.setText("" + ozOne);
}
// Table Spoon to Table Spoon
if (spinnerFromOne.equals("Table Spoon(tbsp)") && spinnerToOne.equals("Table Spoon(tbsp)")) {
textview3ToConvert.setText("" + tbsp);
}
// Tea Spoon to Tea Spoon
if (spinnerFromOne.equals("Tea Spoon(tsp)") && spinnerToOne.equals("Tea Spoon(tsp)")) {
textview3ToConvert.setText("" + tsp);
}
// Tea Spoon to Ounces
if (spinnerFromOne.equals("Tea Spoon(tsp)") && spinnerToOne.equals("Ounces(oz)")) {
textview3ToConvert.setText("" + ozTwo);
}
// Tea Spoon to Table Spoon
if (spinnerFromOne.equals("Tea Spoon(tsp)") && spinnerToOne.equals("Table Spoon(tbsp)")) {
textview3ToConvert.setText("" + tbspOne);
}
// Ounces to Tea Spoon
if (spinnerFromOne.equals("Ounces(oz)") && spinnerToOne.equals("Tea Spoon(tsp)")) {
textview3ToConvert.setText("" + tspTwo);
}
// Ounces to Ounces
if (spinnerFromOne.equals("Ounces(oz)") && spinnerToOne.equals("Ounces(oz)")) {
textview3ToConvert.setText("" + oz);
}
// Ounces to Table Spoon
if (spinnerFromOne.equals("Ounces(oz)") && spinnerToOne.equals("Table Spoon(tbsp)")) {
textview3ToConvert.setText("" + tbspTwo);
}
break;
}
这是我的相等按钮,所有功能都在其中起作用。