How to disable future date picker in android

后端 未结 4 606
情话喂你
情话喂你 2020-12-22 13:27

I\'m new to android How to do disable future date in date picker, I tried many codes in stack over flow but it couldn\'t help.can anybody help me pleas.

Have a look

4条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-22 14:17

    I use this code in my project:

     Calendar calendar = Calendar.getInstance();
                                calendar.set(year,monthOfYear,dayOfMonth);
    
                                long selectedTimeInMillis = calendar.getTimeInMillis();
                                long systemTimeInMillis = Calendar.getInstance().getTimeInMillis();
                                if(selectedTimeInMillis<=systemTimeInMillis){
                                    setDate(year,monthOfYear,dayOfMonth);
                                }else{
                                    Toast.makeText(getContext(),"Cannot select future date",Toast.LENGTH_SHORT).show();
                                }
    

提交回复
热议问题