datepicker - Android: Getting previous date in DatePickerDialog -


i'm displaying datepickerdialog restricting previous date using datepickerdialog.getdatepicker().setmindate(system.currenttimemillis());. in case not activating previous dates , restricting previous months user still able select previous date of present month (for understanding see image , code)

enter image description here

etdate.setonclicklistener(new onclicklistener() {          @override         public void onclick(view v) {              final calendar mcurrentdate = calendar.getinstance();             int myear = mcurrentdate.get(calendar.year);             int mmonth = mcurrentdate.get(calendar.month);             int mday = mcurrentdate.get(calendar.day_of_month);               datepickerdialog datepickerdialog = new datepickerdialog(eventmyeventedit.this, new ondatesetlistener() {                  @override                 public void ondateset(datepicker view, int year, int monthofyear,                         int dayofmonth) {                      mcurrentdate.set(calendar.year, year);                      mcurrentdate.set(calendar.month, monthofyear);                      mcurrentdate.set(calendar.day_of_month,dayofmonth);                      string myformat = "dd/mm/yy";                      simpledateformat sdf = new simpledateformat(myformat, locale.us);                       etdate.settext(sdf.format(mcurrentdate.gettime()));                  }             }, myear, mmonth, mday);              datepickerdialog.getdatepicker().setmindate(system.currenttimemillis());              datepickerdialog.show();          }     }); 

edit: want restrict user when selecting previous dates present date

i had same problem , resolve changing theme of datepickerdialog.i dont know why depends on theme in case worked me

use following code

 datepickerdialog _date = new datepickerdialog(this, alertdialog.theme_holo_light, datepickerlistener, myear, mmonth,                         mday) {                     @override                     public void ondatechanged(datepicker view, int year, int monthofyear, int dayofmonth) {                          view.setspinnersshown(true);                         calendar c = calendar.getinstance();                         int myear = c.get(calendar.year);                         int mmonth = c.get(calendar.month);                         int mday = c.get(calendar.day_of_month);                          if (year < myear)                             view.updatedate(myear, mmonth, mday);                          if (monthofyear < mmonth && year == myear)                             view.updatedate(myear, mmonth, mday);                          if (dayofmonth < mday && year == myear && monthofyear == mmonth)                             view.updatedate(myear, mmonth, mday);                      }                 }; 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -