enter image description here

In my android application for an EditText with number input type, I want to trigger an action as the cross(cancel) button is clicked from the numeric keypad like "Done" button but unable to trigger. Here what I am trying. Thanks

pinNum3.setOnEditorActionListener(new TextView.OnEditorActionListener() {
            @Override
            public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {

                if (actionId == EditorInfo.IME_ACTION_PREVIOUS) {

                    pinNum2.requestFocus();
                    return true;
                }
                return false;
            }
        });

1 Answers

1
pab On Best Solutions

Try setting key listener instead of Editor Action listener as this will trigger keypress

editText.setOnKeyListener(new View.OnKeyListener() {
    @Override
    public boolean onKey(View v, int keyCode, KeyEvent event) {
        if(keyCode == KeyEvent.KEYCODE_DEL){
             editText.setText("");
        }
    return false;
    }
});