如果/没有在按钮内按下内部方法按下

时间:2013-02-28 14:06:27

标签: android if-statement

所以我有一个按下按钮的方法,一切都很完美,除非我有一些内部的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;
}

3 个答案:

答案 0 :(得分:4)

澄清:=用于分配目的,例如int x = 10;==用于比较,例如boolean isX10 = x==10;

你的if声明错误了:

 if (hourType == false) { // Not hitting this point for some reason I
                            // can't fathom.

 if (!hourType) { // Not hitting this point for some reason I
                            // can't fathom.

而不是

 if (hourType = false) { // Not hitting this point for some reason I
                            // can't fathom.

答案 1 :(得分:2)

可能hourType = false应为hourType == false,或者更好!hourType

答案 2 :(得分:0)

if if else如果两者都在错误的语法中检查相同的条件,它应该是

 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 == true) {
                if (moodHour <= 0) {
                    moodHour = 12;
                }

 if (!hourType) { // Not hitting this point for some reason I
                                        // can't fathom.
                    if (moodHour > 12) {
                        moodHour = (moodHour - 12);
                        moodAntePost = "PM";
                    }
                } else if (hourType) {
                    if (moodHour <= 0) {
                        moodHour = 12;
                    }