0

在我的应用程序中,我正在从数据库中获取数据,因为我也在获取日期。因此,如果用户单击任何特定项目意味着我也会获取该开始日期,并且我必须将其设置为屏幕中 dat 选择器中的默认日期。现在获取数据是正确的,如果我单击设置,则会出现 1 个对话框,其中包含 2 个选项“SET”和“CANCEL”的获取数据意味着获取的日期不是默认日期,只有当前日期是默认日期。帮助我..提前谢谢。

我的编码:

 c = Calendar.getInstance();               
               SimpleDateFormat sdf=new SimpleDateFormat("yyyy/MM/dd");
               System.out.println("After format");
               Date pickdefdate=null;
               String pickdefdatepar=null;
               try {
                   System.out.println("Inside try="+date);
              pickdefdate=sdf.parse(date);
              System.out.println("dddddddd="+pickdefdate);

              c.setTime(pickdefdate);
              System.out.println("After parse");
            } catch (ParseException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
               System.out.println("B4 setting");

               mYear = c.get(Calendar.YEAR);
               mMonth = c.get(Calendar.MONTH);
               mDay = c.get(Calendar.DAY_OF_MONTH);           
               showDialog(DATE_DIALOG_ID);


protected Dialog onCreateDialog(int id) 
     {
            switch (id) {
            case DATE_DIALOG_ID:
                System.out.println("in dia="+mDay);
                return new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
            }
            return null;
        }


     private DatePickerDialog.OnDateSetListener mDateSetListener =
                new DatePickerDialog.OnDateSetListener() {
                    public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
                        System.out.println("Inside dia");
                        mYear = year;
                        mMonth = monthOfYear;
                        mDay = dayOfMonth;
                    }
            };        
4

1 回答 1

0

You have to extend onPrepareDialog function

 @Override

protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case date_picker_dialog_show:
((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
break;
}}

this will update the date picker date when it show

于 2012-08-11T09:10:15.540 回答