2011-02-17 59 views
1

我需要檢查輸入鍵來啓動搜索例程。除一些鍵盤外的所有作品似乎都有一個SEND按鈕,而不是ENTER按鈕。當這個按下時代碼轉儲。下面有一個小樣本。有任何想法嗎?android SEND鍵崩潰

tx1.setOnEditorActionListener (new OnEditorActionListener() { 
    @Override 
    public boolean onEditorAction(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) { 
       // ... 
      } 
     } 
    } 
} 
+1

使用`ADB logcat`,DDMS,或在Eclipse中DDMS角度來考察logcat的,並期待在堆棧跟蹤你的「代碼轉儲」。 – CommonsWare 2011-02-17 23:22:13

+0

請格式化您粘貼的代碼。我幫助更輕鬆! – WarrenFaith 2011-02-17 23:25:30

回答

2

我相信事件在這種情況下爲空。爲了檢測軟鍵盤上的發送動作,你的onEditorActionListener實際上應該這樣做。

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' 
}