在按钮上单击显示DatePickerDialog

时间:2014-05-05 17:19:55

标签: android

我想在点击按钮时显示DatePickerdialog? 现在我尝试了这段代码:

  btn_end_date.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            Calendar c = Calendar.getInstance();
            int myyear = c.DATE ;
            int mymonth = c.MONTH;
            int mydate = c.YEAR ;

            DatePickerDialog ddp = new DatePickerDialog( getApplicationContext(), new OnDateSetListener() {

                @Override
                public void onDateSet(DatePicker view, int year, int monthOfYear,
                        int dayOfMonth) {
                    // TODO Auto-generated method stub
                    btn_end_date.setText(year+"/"+monthOfYear +"/"+dayOfMonth );
                }
            }, myyear, mymonth,mydate);
            ddp.show();
        }
    });

但这给了我这个错误:

   android.view.windowmanager$badtokenexception unable to add window

那么,我该怎么做呢?

0 个答案:

没有答案