我想在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();

08-18 10:36