Android键盘返回键报错java.lang.IllegalStateException: focus search returned a view that wasn't ab

mac2024-05-14  30

点击键盘的回车键会通过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; } });
最新回复(0)