How do you set min and max dates in an Android DatePicker?

前端 未结 3 1380
渐次进展
渐次进展 2021-01-17 23:11

I am using Android\'s default date picker and my min supported SDK is 10 and I want to set the min and the max dates of the date picker.

Here is what I have in my M

3条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-17 23:55

    i solved this by following

    DatePickerDialog datePickerDialog;
    final Calendar c = Calendar.getInstance();
        int year = c.get(Calendar.YEAR);
        int month = c.get(Calendar.MONTH);
        int day = c.get(Calendar.DAY_OF_MONTH);
        datePickerDialog = new DatePickerDialog(getActivity(), this, year, month, day);
        datePickerDialog.getDatePicker().setMinDate(c.getTimeInMillis());    
    

    hope it will help you

提交回复
热议问题