【问题标题】:My DatePickerDialog not showing the current date. How to get Current date in DatePickerDialog?我的 DatePickerDialog 没有显示当前日期。如何在 DatePickerDialog 中获取当前日期?
【发布时间】:2017-03-31 06:58:45
【问题描述】:

我使用 TimepickerDialog 和 DatePicker Dialog 来获取时间和日期。 但是当打开日期选择器对话框时,它显示不同的日期click to view

这是我的代码。

         final Calendar calendar = Calendar.getInstance();

            dt_day = calendar.get(Calendar.DAY_OF_MONTH);
            dt_month =calendar.get(Calendar.MONTH);
            dt_year = calendar.get(Calendar.YEAR);
           final DatePickerDialog datePickerDialog = new DatePickerDialog(this, new DatePickerDialog.OnDateSetListener() {

            @Override
            public void onDateSet(DatePicker view, int year, int month, int dayOfMonth) {
                 //     datePickerDialog.updateDate(12,12,1993);
                date.setText(dayOfMonth + "/" + (month+1) + "/" + year);
                str_date = String.valueOf(dayOfMonth + "/" + (month+1) + "/" + year);
            }
        },dt_day, dt_month,dt_year);

        datePickerDialog.show();

【问题讨论】:

    标签: android android-alertdialog android-datepicker datepickerdialog


    【解决方案1】:

    你给的参数值错误,第三个参数应该是dt_year,第五个参数应该是dt_day

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2022-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多