Android DatePickerDialog: Set min and max date for selection

前端 未结 6 801
清酒与你
清酒与你 2020-11-30 12:12

I know there are quite a lot of question for this but none of the solutions are working for me, so this question. I want to restrict user to select date before today, but am

6条回答
  •  自闭症患者
    2020-11-30 12:57

    Get System Time and subtract 1 second from It

     @Override
     public Dialog onCreateDialog(Bundle savedInstanceState) {
        Calendar calendar = Calendar.getInstance();
        int year    = calendar.get(Calendar.YEAR);
        int month   = calendar.get(Calendar.MONTH);
        int day     = calendar.get(Calendar.DAY_OF_MONTH);
    
         dialog = new DatePickerDialog(act, listener, year, month, day);
         dialog.getDatePicker().setMinDate(System.currentTimeMillis() -1000);
         return dialog;
     }
    

提交回复
热议问题