Code example for KeyEvent

0
 
    void onDelete() { 
        if (getText().equals(mResult) || mIsError) {
            clear(false); 
        } else { 
            mDisplay.dispatchKeyEvent(new KeyEvent(0, KeyEvent.KEYCODE_DEL));
            mResult = "";
        } 
    } 
 
    void onClear() { 
        clear(mDeleteMode == DELETE_MODE_CLEAR);
    } 
 
    void onEnter() { 
        if (mDeleteMode == DELETE_MODE_CLEAR) {
            clearWithHistory(false); // clear after an Enter on result 
        } else { 
            evaluateAndShowResult(getText(), CalculatorDisplay.Scroll.UP); 
        } 
    }