點擊鍵盤的回車鍵會通過EditableInputConnection來執行onEditorAction方法,異常的原因是查詢上一個或下一個view的焦點的時候失敗了 拋出了異常,這兩處拋出異常的代碼上方有個return,如果能保證
ict.onEditorActionListener.onEditorAction(this, actionCode, null)永遠爲true那麼異常代碼就永遠不會執行
即設置EditText的onEditorActionListener()
//點擊鍵盤返回不報異常
et_search.setOnEditorActionListener(new TextView.OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//可以根據需求獲取下一個焦點還是上一個
View nextView = v.focusSearch(View.FOCUS_DOWN);
if (nextView != null) {
nextView.requestFocus(View.FOCUS_DOWN);
}
//這裏一定要返回true
return true;
}
});