开发者

android SEND key crashes

I have a need to check for the enter key to start a search routine. All works except some keyboards seem to have a SEND button instead of the ENTER button. When this is pressed the code dumps. I have a small sample below. Any ideas?

tx1.setOnEditorActionListener (new OnEditorActionListener() {
    @Override
    public boolean onEd开发者_运维知识库itorAction(TextView v, int actionId, KeyEvent event) {
        System.out.println("Key: " + event.getKeyCode()); //BLOWS UP HERE
        if  (event.getAction() ==  KeyEvent.ACTION_DOWN) {
            if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER) {
                // ...
            }
        }
    }
}


I believe that event is null in this case. for detecting the send action on the softkeyboard your onEditorActionListener should actually just do this.

onEditorAction(TextView v, int actionId, KeyEvent event){
    if(actionId == EditorInfo.IME_ACTION_SEND){
        send();
    }
    return false;// so the softkeyboard will still close after pressing 'send'
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜