开发者

Android DatePicker problem and back button

Well i have an activity with 3 date pickers. The problem is that after setting the desired date values to my form and clicking the back the Datepicker dialog show up again. I click the Cancel button and click back again and i got an FC. From Logcat:

06-28 09:28:57.531: ERROR/AndroidRuntime(2029): java.lang.IllegalArgumentException:       Activity#onCreateDialog did not create a dialog for id 2
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at  android.app.Activity.createDialog(Activity.java:871)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.app.Activity.showDialog(Activity.java:2483)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.util.DialogManager.showDialogInfo(DialogManager.java:63)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.util.ShowConfirmDialogRunnable.run(ShowConfirmDialogRunnable.java:53)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.util.DelegateRunnable.invokePostAndWait(DelegateRunnable.java:59)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.ui.ScreenManager.invokePostAndWait(ScreenManager.java:556)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.ui.ScreenManager.showConfirmDialog(ScreenManager.java:720)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.ui.ScreenManager.exitScreenWithCheck(ScreenManager.java:1046)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at mcrm.android.ui.NewOp开发者_Go百科ptyScreenActivityHelper.onClose(NewOpptyScreenActivityHelper.java:29)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at mcrm.android.ui.NewOpptyScreenActivity.onKeyDown(NewOpptyScreenActivity.java:497)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.view.KeyEvent.dispatch(KeyEvent.java:1037)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.app.Activity.dispatchKeyEvent(Activity.java:2043)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1631)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2368)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2338)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1641)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.os.Handler.dispatchMessage(Handler.java:99)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.os.Looper.loop(Looper.java:123)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.util.ShowConfirmDialogRunnable.run(ShowConfirmDialogRunnable.java:56)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.util.DelegateRunnable.invokePostAndWait(DelegateRunnable.java:59)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.ui.ScreenManager.invokePostAndWait(ScreenManager.java:556)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.ui.ScreenManager.showConfirmDialog(ScreenManager.java:720)
06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.ui.ScreenManager.exitScreenWithCheck(ScreenManager.java:1046)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at mcrm.android.ui.NewOpptyScreenActivityHelper.onClose(NewOpptyScreenActivityHelper.java:29)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at mcrm.android.ui.NewOpptyScreenActivity.onKeyDown(NewOpptyScreenActivity.java:497)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.view.KeyEvent.dispatch(KeyEvent.java:1037)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.app.Activity.dispatchKeyEvent(Activity.java:2043)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchKeyEvent(PhoneWindow.java:1631)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.view.ViewRoot.deliverKeyEventToViewHierarchy(ViewRoot.java:2368)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.view.ViewRoot.handleFinishedEvent(ViewRoot.java:2338)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.view.ViewRoot.handleMessage(ViewRoot.java:1641)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.os.Handler.dispatchMessage(Handler.java:99)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.os.Looper.loop(Looper.java:123)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.util.ShowAlertDialogRunnable.run(ShowAlertDialogRunnable.java:37)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.octanewave.platform.android.util.DelegateRunnable.run(DelegateRunnable.java:19)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.os.Handler.handleCallback(Handler.java:587)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.os.Handler.dispatchMessage(Handler.java:92)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.os.Looper.loop(Looper.java:123)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at android.app.ActivityThread.main(ActivityThread.java:4363)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at java.lang.reflect.Method.invokeNative(Native Method)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at java.lang.reflect.Method.invoke(Method.java:521)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
 06-28 09:28:57.531: ERROR/AndroidRuntime(2029):     at dalvik.system.NativeStart.main(Native Method)

And here is a portion of the code:

mPickDate = (ImageView) findViewById(R.id.pickDate);
  mPickDate.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
         showDialog(DATE_DIALOG_ID);
        }
    });

@Override
protected Dialog onCreateDialog(int id) {
 switch (id) {
 case DATE_DIALOG_ID:
     return new DatePickerDialog(this,
                 mDateSetListener,
                 mYear, mMonth, mDay);
 case DATE_DIALOG_ID_RETURN:
     return new DatePickerDialog(this,
       mDateSetListenerreturn,
                 mYear, mMonth, mDay);     
 }
 return null;
}

 // updates the date in the TextView
    private void updateDisplay(TextView mDateDisplay) {
    mDateDisplay.setText(
        new StringBuilder()
                // Month is 0 based so add 1
               .append(mDay).append("-")
               .append(mMonth + 1).append("-")
               .append(mYear).append("")


                );
}
private DatePickerDialog.OnDateSetListener mDateSetListener =
    new DatePickerDialog.OnDateSetListener() {

        public void onDateSet(DatePicker view, int year, 
                              int monthOfYear, int dayOfMonth) {
            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;
            updateDisplay(mDateDisplay);
        }
    };

...

I changed the 'this' with 'getParent()' at onCreateDialog() but nothing happened Any suggestions?


Your error is on line 63 of DialogManager.java. Without seeing the code, I cannot be any more specific, but it looks as though there is a problem with one of your arguments to showDialog().

You have overridden the onCreateDialog() method as described here, and, if so, create a dialog box when given id = 2, haven't you?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜