我已经实现了微调器,并且“单击”可以正常工作。但是,当我双击旋转器的任何项目时,整个应用程序正在崩溃。基本上用户应该无法双击。我在模拟器上运行代码。由于模拟器速度慢或者我的代码中是否有任何错误,这种情况是不是很明显?
static Spinner statusSpinner;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mySpinner = (Spinner) findViewById(R.id.Spn_Status);
mySpinner.setOnItemSelectedListener(this);
}
@Override
public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
//do something
}
@Override
public void onNothingSelected(AdapterView<?> parent){
//do something
}
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="0dip"
android:weightSum="10" >
<Spinner
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:id="@+id/Spn_Status"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="4"
android:background="@drawable/drop_down"
android:entries="@array/Status"
android:paddingLeft="5dip"
android:prompt="@string/Set_Status"
android:spinnerMode="dialog"/>
</LinearLayout>
logcat的:
java.lang.NullPointerException
at android.widget.Spinner$DialogPopup.dismiss(Spinner.java:907)
at android.widget.Spinner$DialogPopup.onClick(Spinner.java:945)
at com.android.internal.app.AlertController$AlertParams$3.onItemClick(AlertController.java:941)
at android.widget.AdapterView.performItemClick(AdapterView.java:298)
at android.widget.AbsListView.performItemClick(AbsListView.java:1100)
at android.widget.AbsListView$PerformClick.run(AbsListView.java:2788)
at android.widget.AbsListView$1.run(AbsListView.java:3463)
at android.widget.AbsListView.onDetachedFromWindow(AbsListView.java:2670)
at android.view.View.dispatchDetachedFromWindow(View.java:12160)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2570)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2568)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2568)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2568)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2568)
at android.view.ViewGroup.dispatchDetachedFromWindow(ViewGroup.java:2568)
at android.view.ViewRootImpl.dispatchDetachedFromWindow(ViewRootImpl.java:2820)
at android.view.ViewRootImpl.doDie(ViewRootImpl.java:5162)
at android.view.ViewRootImpl$ViewRootHandler.handleMessage(ViewRootImpl.java:3148)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)