jeudi 20 avril 2017

Weird if/else behavior Android

I'm trying to cacth done action which comes from softkeyboard. My code is like this;

    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;
            }
        }
    };
}

However even though IDE evaluates "(actionId == EditorInfo.IME_ACTION_DONE)"as true, it's not calling nextPage(), returning false instead. If I cast expression like this, it works fine.

    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;
            }
        }
    };
}

Any idea what can cause this?

Aucun commentaire:

Enregistrer un commentaire