Android 애플리케이션에서 문제가 발생했습니다. 문제는 어떤 이유로 ListPreference
내 preferences.xml
파일 에서 문자열을 검색 할 수 없다는 것 입니다. 내가 시도한 코드는 다음과 같습니다.
private void showUserSettings() {
SharedPreferences sharedPrefs = PreferenceManager
.getDefaultSharedPreferences(this);
try {
String feet = sharedPrefs.getString("feet", "NULL");
int intfeet = Integer.parseInt(feet);
int intinches = Integer.parseInt(sharedPrefs.getString("feet", "NULL").trim());
int weight = Integer.parseInt(sharedPrefs.getString("weight", "NULL").trim());
int age = Integer.parseInt(sharedPrefs.getString("age", "NULL").trim());
double calories;
double inches = ((intfeet * 12) + intinches);
if (gender.equals("Female")) {
//BMR = 655 + ( 4.35 x weight in pounds ) + ( 4.7 x height in inches ) - ( 4.7 x age in years )
calories = 655 + (4.35 * weight) + (4.7 * inches) - (4.7 * age);
}
else {
//66 + ( 6.23 x weight in pounds ) + ( 12.7 x height in inches ) - ( 6.8 x age in years )
calories = 66.5 + (6.23 * weight) + (12.7 * inches) - (6.8 * age);
}
//ListPreference listPreference = (ListPreference) findPreference("exercise");
//CharSequence currText = listPreference.getEntry();
String exercise = sharedPrefs.getString("exercise", "NULL").toString();
if (exercise.equals("Sedentary")) {
double sedentary = calories * 1.2;
Toast.makeText(getApplicationContext(), sedentary + "", Toast.LENGTH_LONG).show();
}
if (exercise.equals("Light")){
double light = calories * 1.375;
Toast.makeText(getApplicationContext(), light + "", Toast.LENGTH_LONG).show();
}
if (exercise.equals("Moderate")){
double moderate = calories * 1.55;
Toast.makeText(getApplicationContext(), moderate + "", Toast.LENGTH_LONG).show();
}
if (exercise.equals("Very active")) {
double veryactive = calories * 1.725;
Toast.makeText(getApplicationContext(), veryactive + "", Toast.LENGTH_LONG).show();
}
if (exercise.equals("Extra active")) {
double extraactive = calories * 1.9;
Toast.makeText(getApplicationContext(), extraactive + "", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(getApplicationContext(), "Uh oh", Toast.LENGTH_SHORT).show();
}
}catch (Exception e) {
e.printStackTrace();
}
}
두 번째 if / else 문에 도달 할 때마다 else 문으로 직접 이동합니다. 왜 이런 일을하는지 모르겠습니다. 나는 SO와 Google을 검색했지만 아무 소용이 없습니다. 기본적으로 벽돌 벽에 부딪 혔습니다. 이 문제에 대한 도움을 주시면 감사하겠습니다.
모든 운동 조건은 별개이며 나머지는 마지막 if 문에만 연결됩니다. else if
내가 생각하는 방식으로 모두 함께 묶는 데 사용 합니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다