EditText OnKeyDown

后端 未结 1 796
臣服心动
臣服心动 2020-12-20 15:48

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 ca

相关标签:
1条回答
  • 2020-12-20 16:38

    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;
                }
            });
    
    0 讨论(0)
提交回复
热议问题