开发者

Soft keyboard enter key event handle

开发者 https://www.devze.com 2023-04-09 07:59 出处:网络
I want to do some stuff on soft keyboard enter key press. See my code and output below. It executes twice, 开发者_开发百科but I want it to be executed only once. How to fix it?

I want to do some stuff on soft keyboard enter key press. See my code and output below. It executes twice, 开发者_开发百科but I want it to be executed only once. How to fix it?

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    txt = (EditText)findViewById(R.id.txt);
    txt.setOnKeyListener(new OnKeyListener() {

        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {
            if (keyCode == KeyEvent.KEYCODE_ENTER) {
                Log.e("test","--------- on enter");
                return false;
            }
            return false;
        }
    });
}

Soft keyboard enter key event handle


The best way possible:

if (keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN) {
    Log.d(TAG, "enter_key_called");
}
0

精彩评论

暂无评论...
验证码 换一张
取 消