Android DatePickerDialog - 隐藏过去的日期

Android DatePickerDialog - hide past dates

我想在 Fragment 的 DatePickerDialog 中隐藏过去的日期。为此,我正在使用:

 datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);      

但它向我显示错误...无法在 Fragment

中解决此方法 "getDatePicker"

有什么想法吗??? THnx 提前

  public  void showDatePicker() {
            datePickerDialog = DatePickerDialog.newInstance(
                    this,
                    dateTime.get(Calendar.YEAR),
                    dateTime.get(Calendar.MONTH),
                    dateTime.get(Calendar.DAY_OF_MONTH));
            datePickerDialog.setYearRange(dateTime.get(Calendar.YEAR), dateTime.get(Calendar.YEAR) + 1);
            datePickerDialog.setCancelable(true);
            datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
            datePickerDialog.show(getChildFragmentManager(), TAG + "datePickerDialog");
        }

试试这个,

    Calendar calendar=Calendar.getInstance();           
    DatePickerDialog dialog=new DatePickerDialog(this, new OnDateSetListener() {                        

                    @Override
                    public void onDateSet(DatePicker view, int year, int monthOfYear,
                            int dayOfMonth) {

                        //your code
                    }
                }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH), calendar.get(Calendar.DAY_OF_MONTH)); 

    dialog.getDatePicker().setMinDate(calendar.getTimeInMillis());
    dialog.show();

看看这是否有效

 public  void showDatePicker() {
        datePickerDialog = DatePickerDialog.newInstance(
                this,
                dateTime.get(Calendar.YEAR),
                dateTime.get(Calendar.MONTH),
                dateTime.get(Calendar.DAY_OF_MONTH));
        datePickerDialog.setYearRange(dateTime.get(Calendar.YEAR), dateTime.get(Calendar.YEAR) + 1);
        datePickerDialog.setCancelable(true);
        Field mDatePickerField = datePickerDialog .getClass().getDeclaredField("mDatePicker");
        mDatePickerField.setAccessible(true);
        DatePicker mDatePicker = (DatePicker) mDatePickerField.get(datePickerDialog);
        mDatePicker.setMinDate(System.currentTimeMillis() - 1000);
        datePickerDialog.show(getChildFragmentManager(), TAG + "datePickerDialog");
    }