1
我正在編寫應用程序,在此應用程序中我編輯了文本。我想當用戶在編輯文本末尾寫入一些文本然後按下回車按鈕時,我想讓它調用一些命令。這是我所做的。這是ICS的工作,但是當我嘗試其他設備(Jelly Bean)時,它不起作用。在果凍豆上處理「Enter」鍵
inputViaTextChatbot.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if ((event != null && (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) || (actionId == EditorInfo.IME_ACTION_DONE)) {
// hide the keyboard
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(v.getWindowToken(), 0);
// process
getThis = inputViaTextChatbot.getText().toString();
if (getThis!=null && getThis.length()>1) {
try {
Log.v("Got This: ", getThis);
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
inputViaTextChatbot.setText("");
}
}
return false;
}
});
任何人都可以幫助我做到這一點?