Skip to content Skip to sidebar Skip to footer

Edittext Onkeydown

I have declared an EditText programmatically (i.e. not in XML), and want to apply an OnKeyDown handler to it. The code shown does not work. The context is, I'm trying to capture a

Solution 1:

You must bind the onKeyListener to your editText.

myEditText.setOnKeyListener(new OnKeyListener() {           
            @Override
            public boolean onKey(View v, int keyCode, KeyEvent event) {
                if (event.getAction()==KeyEvent.ACTION_DOWN && keyCode == KeyEvent.KEYCODE_ENTER) {
                    //do something here
                    return true;
                }
                return false;
            }
        });

Post a Comment for "Edittext Onkeydown"