setOnEditorActionListener not working with soft keyboard submit button, but does with laptop Enter key?

后端 未结 5 1778
北荒
北荒 2021-01-12 02:47

Can someone please provide a solution to get a working listener for the soft-keyboard DONE button, and/or explain what I\'m doing wrong in my current approach?<

5条回答
  •  耶瑟儿~
    2021-01-12 03:16

    Try this,

        ((EditText) findViewById(R.id.comment_text)).setOnEditorActionListener(new TextView.OnEditorActionListener() {
                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
    
        if (event != null && (actionId == EditorInfo.IME_ACTION_GO
                                || event.getKeyCode() == event.KEYCODE_ENTER))
        {
        //do whatever you want
        }
    
                    }
                });
    
    
    
     
    

提交回复
热议问题