datetimepicker - disable selection of past months and enable selection on future month and date in materialdatetimepicker in android -


integrating https://github.com/wdullaer/materialdatetimepicker library in android app,here code select date , time.i'm able implement enabling future date in month , disable past date in month want implement disable option past months , enable selection option future months.here code

private void selectdate() {     final timepickerdialog timepickerdialog12h = timepickerdialog             .newinstance(new ontimesetlistener() {                  @override                 public void ontimeset(radialpickerlayout view,                         int hourofday, int minute) {                      object c = pad3(hourofday);                     selectedtime = new stringbuilder()                             .append(pad2(hourofday)).append(":")                             .append(pad(minute)).append(c);                      string str_date = selecteddate.tostring() + " "                             + selectedtime + "";                     string str_date_current = currentdate.tostring() + " "                             + mcalendar.get(calendar.hour_of_day) + ":"                             + mcalendar.get(calendar.minute);                      dateformat formatter = new simpledateformat(                             "dd-mm-yyyy hh:mm aa");                     dateformat formatter2 = new simpledateformat(                             "dd-mm-yyyy hh:mm");                     dateformat myformat = new simpledateformat(                             "yyyy-mm-dd hh:mm:ss");                      try {                         string reformattedstr = myformat.format(formatter                                 .parse(str_date));                         // date date=formatter.parse(str_date);                         string reformattedstr2 = myformat.format(formatter2                                 .parse(str_date_current));                          date = (date) myformat.parse(reformattedstr);                         date date2 = (date) myformat.parse(reformattedstr2);                          if (date2.before(date)) {                             bookappointment();                         } else {                              selectdate();                             toast.maketext(                                     chatthread.this,                                     "we wish go in past ;)",                                     toast.length_short).show();                         }                         system.out.println("today " + date.gettime());                      } catch (parseexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }                  }             }, mcalendar.get(calendar.hour_of_day), mcalendar                     .get(calendar.minute), false);      datepickerdialog = datepickerdialog.newinstance(             new ondatesetlistener() {                  public void ondateset(datepickerdialog datepickerdialog,                         int year, int month, int day) {                      selecteddate = new stringbuilder().append(pad(day))                             .append("-")                             .append(mcalendar.get(calendar.month) + 1)                             .append("-")                             .append(mcalendar.get(calendar.year));                      currentdate = new stringbuilder()                             .append(mcalendar.get(calendar.day_of_month))                             .append("-").append(pad(month + 1)).append("-")                             .append(pad(year));                     dateformat format = new simpledateformat("dd-mm-yyyy");                     try {                         date date1 = format.parse(selecteddate.tostring());                         date date2 = format.parse(currentdate.tostring());                         calendar cal = calendar.getinstance();                         cal.settime(date2);                         datepickerdialog.setmindate(cal);                          if (date2.equals(date1) || date2.compareto(date1)<0) {                             timepickerdialog12h.show(getfragmentmanager(),                                     "");                          } else {                             selectdate();                             toast.maketext(                                     chatthread.this,                                     "we wish go in past ;)",                                     toast.length_short).show();                         }                      } catch (parseexception e) {                         // todo auto-generated catch block                         e.printstacktrace();                     }                  }              }, mcalendar.get(calendar.year), mcalendar.get(calendar.month),             mcalendar.get(calendar.day_of_month));      // datepickerdialog.oncreatedialog(savedinstancestate)      datepickerdialog.show(getfragmentmanager(), "tag"); } 

to achieve in materialdatetimepicker should set minimum date

calendar cal = calendar.getinstance();             cal.get(calendar.year);             cal.get(calendar.month);             cal.get(calendar.day_of_month);             dpd.setmindate(cal); 

so datepickerdialog below code

datepickerdialog dpd = datepickerdialog.newinstance(                             addtask.this,                             calendar.get(calendar.year),                             calendar.get(calendar.month),                             calendar.get(calendar.day_of_month)                     );                  dpd.setthemedark(true);                 dpd.vibrate(true);                 dpd.dismissonpause(true);                 dpd.showyearpickerfirst(false);                 calendar cal = calendar.getinstance();             cal.get(calendar.year);             cal.get(calendar.month);             cal.get(calendar.day_of_month);             dpd.setmindate(cal);                 dpd.setaccentcolor(getresources().getcolor(r.color.dark_orange));                 dpd.settitle("date picker");                 dpd.show(getfragmentmanager(), "date picker"); 

Comments

Popular posts from this blog

javascript - Karma not able to start PhantomJS on Windows - Error: spawn UNKNOWN -

c# - Display ASPX Popup control in RowDeleteing Event (ASPX Gridview) -

Nuget pack csproj using nuspec -