在DatePickerDialog之后,AlertDialog崩溃了

时间:2012-08-29 08:19:00

标签: android alertdialog datepickerdialog

全部嗨!

如果我显示DatePickerDialog并单击按钮否定,接下来我想显示AlertDialog但他崩溃了。如果我显示DatePickerDialog并单击button_positive - 那么一切都很好(AlertDialog可以显示)。

protected Dialog onCreateDialog(int id) {
        if (id == DIALOG_DATE) {
            final DatePickerDialog tpd = new DatePickerDialog(this, myCallBack, 2000, 02, 02);
            tpd.setOnShowListener(new DialogInterface.OnShowListener() {
                public void onShow(final DialogInterface dialog) {
                    Button d = tpd.getButton(DatePickerDialog.BUTTON_NEGATIVE);
                    d.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View view) {
                            tpd.dismiss();
                        }
                    });
                }
            });
            return tpd;
        }
        if (id == DIALOG_ABOUT) {
            final LinearLayout view = (LinearLayout) getLayoutInflater()
                    .inflate(R.layout.dialog_about, null);
            final AlertDialog adb = new AlertDialog.Builder(this)
                    .setView(view)
                    .setTitle("О программе")
                    .setIcon(android.R.drawable.ic_dialog_info)
                    .setPositiveButton(R.string.next,
                            new Dialog.OnClickListener() {
                                public void onClick(DialogInterface d, int which) {
                                    // Do nothing here. We override the onclick
                                }
                            }).create();

            adb.setOnShowListener(new DialogInterface.OnShowListener() {

                public void onShow(final DialogInterface dialog) {

                    Button b = adb.getButton(AlertDialog.BUTTON_POSITIVE);
                    b.setOnClickListener(new View.OnClickListener() {
                        public void onClick(View view) {
                            adb.dismiss();
                        }
                    });
                }
            });
            return adb;

        }
        return super.onCreateDialog(id);
    }
  

08-29 08:18:12.080:E / AndroidRuntime(454):致命异常:主要08-29   08:18:12.080:E / AndroidRuntime(454):java.lang.ClassCastException:   android.app.AlertDialog 08-29 08:18:12.080:E / AndroidRuntime(454):at   ru.pososhok.app.stp1.onPrepareDialog(stp1.java:421)08-29   08:18:12.080:E / AndroidRuntime(454):at   android.app.Activity.onPrepareDialog(Activity.java:2515)08-29   08:18:12.080:E / AndroidRuntime(454):at   android.app.Activity.showDialog(Activity.java:2565)08-29   08:18:12.080:E / AndroidRuntime(454):at   android.app.Activity.showDialog(Activity.java:2524)08-29   08:18:12.080:E / AndroidRuntime(454):at   ru.pososhok.app.menu.onOptionsItemSelected(menu.java:36)08-29   08:18:12.080:E / AndroidRuntime(454):at   android.app.Activity.onMenuItemSelected(Activity.java:2205)08-29   08:18:12.080:E / AndroidRuntime(454):at   com.android.internal.policy.impl.PhoneWindow.onMenuItemSelected(PhoneWindow.java:748)   08-29 08:18:12.080:E / AndroidRuntime(454):at   com.android.internal.view.menu.MenuItemImpl.invoke(MenuItemImpl.java:143)   08-29 08:18:12.080:E / AndroidRuntime(454):at   com.android.internal.view.menu.MenuBuilder.performItemAction(MenuBuilder.java:855)   08-29 08:18:12.080:E / AndroidRuntime(454):at   com.android.internal.view.menu.IconMenuView.invokeItem(IconMenuView.java:532)   08-29 08:18:12.080:E / AndroidRuntime(454):at   com.android.internal.view.menu.IconMenuItemView.performClick(IconMenuItemView.java:122)   08-29 08:18:12.080:E / AndroidRuntime(454):at   android.view.View $ PerformClick.run(View.java:9080)08-29 08:18:12.080:   E / AndroidRuntime(454):at   android.os.Handler.handleCallback(Handler.java:587)08-29   08:18:12.080:E / AndroidRuntime(454):at   android.os.Handler.dispatchMessage(Handler.java:92)08-29   08:18:12.080:E / AndroidRuntime(454):at   android.os.Looper.loop(Looper.java:123)08-29 08:18:12.080:   E / AndroidRuntime(454):at   android.app.ActivityThread.main(ActivityThread.java:3683)08-29   08:18:12.080:E / AndroidRuntime(454):at   java.lang.reflect.Method.invokeNative(Native Method)08-29   08:18:12.080:E / AndroidRuntime(454):at   java.lang.reflect.Method.invoke(Method.java:507)08-29 08:18:12.080:   E / AndroidRuntime(454):at   com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:839)   08-29 08:18:12.080:E / AndroidRuntime(454):at   com.android.internal.os.ZygoteInit.main(ZygoteInit.java:597)08-29   08:18:12.080:E / AndroidRuntime(454):at   dalvik.system.NativeStart.main(原生方法)

0 个答案:

没有答案