我正在创建一个转换计算器,其中我有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;
}
这是我的相同按钮,其中每个功能都在工作。