如何将变量fTdee传递到另一个活动中?我似乎有问题,因为fTdee是在If-Else语句中声明的,但我认为我实际上并未从If-Else语句外部访问此变量fTdee。
final float fAF;
float fTdee;
String strAF = tvAF.getText().toString();
if (strAF.matches("OptionA"))
{
fAF = 1.20f;
fTdee = bmr*fAF;
}
else if (strAF.matches("OptionB"))
{
fAF = 1.375f;
fTdee = bmr*fAF;
}
else if (strAF.matches("OptionC"))
{
fAF = 1.55f;
fTdee = bmr*fAF;
}
else if (strAF.matches("OptionD"))
{
fAF = 1.725f;
fTdee = bmr*fAF;
}
else if (strAF.matches("OptionE"))
{
fAF = 1.90f;
fTdee = bmr*fAF;
}
Intent in2 = new Intent(getApplicationContext(), CaloriesPage.class);
in2.putExtra("mTdee",fTdee);
startActivity(in2);
在声明fTdee
之外声明。并且不要制作它们,final
这意味着您无法在实例化后对其进行修改。
float fAF = 0.0f;
String strAF = tvAF.getText().toString();
if (strAF.matches("OptionA")){
fAF = 1.20f;
}else if (strAF.matches("OptionB")){
fAF = 1.375f;
}else if (strAF.matches("OptionC")){
fAF = 1.55f;
}else if (strAF.matches("OptionD")){
fAF = 1.725f;
}else if (strAF.matches("OptionE")){
fAF = 1.90f;
}
final float fTdee = bmr*fAF;
Intent in2 = new Intent(getApplicationContext(), CaloriesPage.class);
in2.putExtra("mTdee",fTdee);
startActivity(in2);
提示:使用更好的var名称
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句