所以我有一个方法可以在按下按钮时运行,一切都很完美,除了我有一点内部 if/else if/else 循环。我确定这是我想念的愚蠢的东西,但我似乎看不到它。
在下面的代码中,我找到了小时类型,但即使我直接将其设置为 false,if/else 也不会触发。它能够很好地获得小时 int,但它不会像预期的那样从中减去 12。
我知道我没有在这里指定日期类型,因为我之前已经这样做了。这不是这里的问题。就像我说的那样,我确定我错过了一些愚蠢的东西,因为我已经盯着它太久了。这是方法:
public String enterMood(View v) {
try {
int month = dPick.getMonth();
int day = dPick.getDayOfMonth();
int year = dPick.getYear();
int minute = tPick.getCurrentMinute();
String moodAntePost = "AM";
hourType = tPick.is24HourView();
moodHour = tPick.getCurrentHour();
if (hourType = false) { // Not hitting this point for some reason I
// can't fathom.
if (moodHour > 12) {
moodHour = (moodHour - 12);
moodAntePost = "PM";
}
} else if (hourType = false) {
if (moodHour <= 0) {
moodHour = 12;
}
} else {
}
String noteText = noteField.getText().toString();
Mood = "Happiness," + happyValue + ",Energy," + energyValue
+ ",Anxiety," + anxietyValue + ",Pain," + painValue
+ ",Date," + month + "/" + day + "/" + year + ",Time,"
+ moodHour + ":" + minute + "," + moodAntePost + ",Note,"
+ noteText;
System.out.println(Mood); //Just to print to the LogCat
} catch (Exception buttonListenerException) {
Log.e(TAG, "Exception received", buttonListenerException);
}
return Mood;
}