Android:将焦点转移到Click上的下一个TextView

时间:2014-09-05 12:23:53

标签: android view focus listener

我有几个带有OnItemSelectListeners的AutoCompleteTextViews,因为我希望在选择了一个条目时,焦点转移到下一个文本字段。我已经阅读了相关问题的答案Focus next textview automatically,它让我了解了如何获得下一个可聚焦的项目,但它没有用。

我的OnClickListener:

OnItemClickListener nextListener = new OnItemClickListener() {
@Override
  public void onItemClick(AdapterView<?> parent, View view, int position, long id){
  view.focusSearch(View.FOCUS_RIGHT).requestFocus();
}
};

这会导致应用崩溃。我也尝试过使用findNextFocus的东西,但是也没办法。我错过了什么?任何帮助表示赞赏。

logcat的: 09-05 14:42:36.732: E/AndroidRuntime(10646): FATAL EXCEPTION: main 09-05 14:42:36.732: E/AndroidRuntime(10646): Process: cau.swp.babsi, PID: 10646 09-05 14:42:36.732: E/AndroidRuntime(10646): java.lang.NullPointerException 09-05 14:42:36.732: E/AndroidRuntime(10646): at cau.swp.babsi.gui.AntibioticActivity$1.onItemClick(AntibioticActivity.java:62) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.widget.AutoCompleteTextView.performCompletion(AutoCompleteTextView.java:902) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.widget.AutoCompleteTextView.access$500(AutoCompleteTextView.java:91) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.widget.AutoCompleteTextView$DropDownItemClickListener.onItemClick(AutoCompleteTextView.java:1192) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.widget.AdapterView.performItemClick(AdapterView.java:299) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.widget.AbsListView.performItemClick(AbsListView.java:1113) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.widget.AbsListView$PerformClick.run(AbsListView.java:2911) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.widget.AbsListView$3.run(AbsListView.java:3645) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.os.Handler.handleCallback(Handler.java:733) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.os.Handler.dispatchMessage(Handler.java:95) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.os.Looper.loop(Looper.java:136) 09-05 14:42:36.732: E/AndroidRuntime(10646): at android.app.ActivityThread.main(ActivityThread.java:5001) 09-05 14:42:36.732: E/AndroidRuntime(10646): at java.lang.reflect.Method.invokeNative(Native Method) 09-05 14:42:36.732: E/AndroidRuntime(10646): at java.lang.reflect.Method.invoke(Method.java:515) 09-05 14:42:36.732: E/AndroidRuntime(10646): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 09-05 14:42:36.732: E/AndroidRuntime(10646): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 09-05 14:42:36.732: E/AndroidRuntime(10646): at dalvik.system.NativeStart.main(Native Method) 09-05 14:42:39.094: E/AndroidRuntime(10710): FATAL EXCEPTION: main 09-05 14:42:39.094: E/AndroidRuntime(10710): Process: cau.swp.babsi, PID: 10710 09-05 14:42:39.094: E/AndroidRuntime(10710): java.lang.RuntimeException: Unable to start activity ComponentInfo{cau.swp.babsi/cau.swp.babsi.gui.ChecklistActivity}: java.lang.NullPointerException 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.app.ActivityThread.access$800(ActivityThread.java:135) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.os.Handler.dispatchMessage(Handler.java:102) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.os.Looper.loop(Looper.java:136) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.app.ActivityThread.main(ActivityThread.java:5001) 09-05 14:42:39.094: E/AndroidRuntime(10710): at java.lang.reflect.Method.invokeNative(Native Method) 09-05 14:42:39.094: E/AndroidRuntime(10710): at java.lang.reflect.Method.invoke(Method.java:515) 09-05 14:42:39.094: E/AndroidRuntime(10710): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785) 09-05 14:42:39.094: E/AndroidRuntime(10710): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601) 09-05 14:42:39.094: E/AndroidRuntime(10710): at dalvik.system.NativeStart.main(Native Method) 09-05 14:42:39.094: E/AndroidRuntime(10710): Caused by: java.lang.NullPointerException 09-05 14:42:39.094: E/AndroidRuntime(10710): at cau.swp.babsi.db.DatabaseAdapter.getDiagnosen(DatabaseAdapter.java:306) 09-05 14:42:39.094: E/AndroidRuntime(10710): at cau.swp.babsi.gui.ChecklistActivity$DiagnoseFragment.onCreateView(ChecklistActivity.java:384) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.support.v4.app.Fragment.performCreateView(Fragment.java:1478) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:927) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1104) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.support.v4.app.FragmentManagerImpl.moveToState(FragmentManager.java:1086) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.support.v4.app.FragmentManagerImpl.dispatchActivityCreated(FragmentManager.java:1877) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.support.v4.app.FragmentActivity.onStart(FragmentActivity.java:552) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.app.Instrumentation.callActivityOnStart(Instrumentation.java:1171) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.app.Activity.performStart(Activity.java:5241) 09-05 14:42:39.094: E/AndroidRuntime(10710): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2157) 09-05 14:42:39.094: E/AndroidRuntime(10710): ... 11 more

抱歉,不知道如何发布logcat更好:/

0 个答案:

没有答案