奇怪的是if / else行为Android

时间:2017-04-20 16:21:59

标签: java android if-statement

我正在尝试完成来自软键盘的动作。我的代码是这样的;

    private TextView.OnEditorActionListener getDoneListener() {
    return new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_DONE) {
                nextPage();
                return true;
            }
            else {
                return false;
            }
        }
    };
}

然而,即使IDE评估“(actionId == EditorInfo.IME_ACTION_DONE)”为true,它也不会调用nextPage(),而是返回false。如果我像这样投射表达式,它可以正常工作。

    private TextView.OnEditorActionListener getDoneListener() {
    return new TextView.OnEditorActionListener() {
        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if ((boolean)(actionId == EditorInfo.IME_ACTION_DONE)) {
                processPayment();
                return true;
            }
            else {
                return false;
            }
        }
    };
}

知道是什么原因引起的吗?

0 个答案:

没有答案