此函数返回 0.0 尽管所有值都是浮动的并且从共享首选项中正确检索!可能是什么错误?
float BMR(){
SharedPreferences customSharedPreference = getSharedPreferences(
"myCustomSharedPrefs", Activity.MODE_PRIVATE);
String Weight =customSharedPreference.getString("weightpref", null);
float weight = Float.valueOf(Weight);
String Height = customSharedPreference.getString("heightpref",null);
float height = Float.valueOf(Height);
String Age = customSharedPreference.getString("agepref", null);
float age = Float.valueOf(Age);
int gender = customSharedPreference.getInt("genderpref", 0);
Toast.makeText(StatsActivity.this, Age, Toast.LENGTH_LONG).show();
if ( gender == 0){
bmr = (float) (10.0 *weight + 6.25 * height - 5.0 * age + 5.0);
}
if(gender == 1){
bmr = (float) (10.0 * weight + 6.25 * height - 5.0 * age- 161.0);
}
String bmrtest = String.valueOf(bmr);
Toast.makeText(StatsActivity.this, "bmr is "+bmrtest, Toast.LENGTH_LONG).show();
return bmr;
}