使用EditText时碰到的一个错误,调试信息如下:
02-10 10:31:58.832: E/AndroidRuntime(802): FATAL EXCEPTION: main
02-10 10:31:58.832: E/AndroidRuntime(802): Process: com.yulore.yellowpage, PID: 802
02-10 10:31:58.832: E/AndroidRuntime(802): java.lang.IllegalStateException: focus search returned a view that wasn't able to take focus!
02-10 10:31:58.832: E/AndroidRuntime(802): at android.widget.TextView.onKeyUp(TextView.java:5659)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.KeyEvent.dispatch(KeyEvent.java:2664)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.View.dispatchKeyEvent(View.java:7665)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1408)
02-10 10:31:58.832: E/AndroidRuntime(802): at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchKeyEvent(PhoneWindow.java:2035)
02-10 10:31:58.832: E/AndroidRuntime(802): at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1505)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.app.Activity.dispatchKeyEvent(Activity.java:2418)
02-10 10:31:58.832: E/AndroidRuntime(802): at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1962)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$ViewPostImeInputStage.processKeyEvent(ViewRootImpl.java:3852)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$ViewPostImeInputStage.onProcess(ViewRootImpl.java:3826)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$AsyncInputStage.forward(ViewRootImpl.java:3525)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$AsyncInputStage.apply(ViewRootImpl.java:3582)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.onDeliverToNext(ViewRootImpl.java:3449)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.forward(ViewRootImpl.java:3418)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.apply(ViewRootImpl.java:3426)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$InputStage.deliver(ViewRootImpl.java:3399)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl.deliverInputEvent(ViewRootImpl.java:5602)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl.doProcessInputEvents(ViewRootImpl.java:5582)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl.enqueueInputEvent(ViewRootImpl.java:5553)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3190)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.os.Handler.dispatchMessage(Handler.java:102)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.os.Looper.loop(Looper.java:136)
02-10 10:31:58.832: E/AndroidRuntime(802): at android.app.ActivityThread.main(ActivityThread.java:5017)
02-10 10:31:58.832: E/AndroidRuntime(802): at java.lang.reflect.Method.invokeNative(Native Method)
02-10 10:31:58.832: E/AndroidRuntime(802): at java.lang.reflect.Method.invoke(Method.java:515)
02-10 10:31:58.832: E/AndroidRuntime(802): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:779)
02-10 10:31:58.832: E/AndroidRuntime(802): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:595)
02-10 10:31:58.832: E/AndroidRuntime(802): at dalvik.system.NativeStart.main(Native Method)
因为我当前的Activity中只有一个EditText能获取到焦点,所以当点击输入法右下角的next时,EditText的右边(或下方)控件不能获取焦点,所以就出现了上述错误。
解决办法
把EditText的android:imeOptions="actionNone" 即可,如下:
<EditText
android:id="@id/et_search"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:layout_toLeftOf="@id/iv_search_delete"
android:layout_toRightOf="@id/iv_sc"
android:background="@null"
android:hint="@string/search_tips"
android:singleLine="true"
android:textColorHint="@color/light_gray"
android:textSize="@dimen/fontsize_14"
android:imeOptions="actionNone"/>