有人告诉我,由于 API 14 的变化,我必须将 switch 语句更改为 If-Else 语句。
没关系。
什么不起作用是当我将插入符号放在 switch 语句上并按照说明按 CTRL-1 时,我没有任何选项,顺便说一下,我正在使用 Ubuntu,有什么建议吗?
我也试过清理我的项目。
编辑。它适用于所有其他 switch 语句,而不是此处包含的语句:
public void onClick(View v) {
switch (v.getId()) {
case R.id.btnCalcCalories:
double weight = Integer.parseInt(etWeight.getText().toString());
double bodyfat = Integer.parseInt(etBodyfat.getText().toString());
;
lbm = weight * (100 - bodyfat) / 100;
bmr = 370 + (21.6 * lbm);
maintCals = bmr * actLevel;
maintCalories
.setText("Calories need to maintain current bodyweight: "
+ String.valueOf(maintCals));
lbmResult.setText("Your Lean Body Mass is " + String.valueOf(lbm)
+ "Kg");
bmrResult.setText("Your Base Metabolic rate is "
+ String.valueOf(bmr) + " calories");
calorieResult.setText("Your Daily calorie goal is "
+ String.valueOf(finalGPercentage) + " calories");
break;
case R.id.btnUpdateDB:
boolean worked = true;
try {
String dbWeight = curWeight.getText().toString();
String dbWaist = curWaist.getText().toString();
String dbChest = curChest.getText().toString();
String dbLegs = curLegs.getText().toString();
String dbArms = curArms.getText().toString();
Stats entry = new Stats(MainActivity.this);
entry.open();
entry.createEntry(dbWeight, dbWaist, dbChest, dbArms, dbLegs);
entry.close();
break;
} catch (Exception e) {
worked = false;
String error = e.toString();
Dialog d = new Dialog(this);
d.setTitle("Error");
TextView tv = new TextView(this);
tv.setText(error);
d.setContentView(tv);
d.show();
} finally {
if (worked) {
Dialog d = new Dialog(this);
d.setTitle("DB Worked");
TextView tv = new TextView(this);
tv.setText("Success");
d.setContentView(tv);
d.show();
}
}
case R.id.btnViewDB:
Intent i = new Intent("com.uhi.fatfighter.DBView");
startActivity(i);
break;
case R.id.btnStopwatchActivity:
Intent s = new Intent("com.uhi.fatfighter.Stopwatch");
startActivity(s);
break;
case R.id.btnMapARun:
Intent m = new Intent("com.uhi.fatfighter.MapRun");
startActivity(m);
break;
case R.id.btnWeightConverter:
Intent w = new Intent("com.uhi.fatfighter.WeightConverter");
startActivity(w);
break;
}
}