android - Get current date on Date Picker Dialog -


i want current date on date picker dialog when user click not working. default date not changing current date. doing wrong in code?

            calendar mcurrentdate = calendar.getinstance();              int day   = mcurrentdate.get(calendar.day_of_month);             int month = mcurrentdate.get(calendar.month);             int year  = mcurrentdate.get(calendar.year);              datepickerdialog dpd;             dpd = new datepickerdialog(getactivity(), 0,                     new datepickerdialog.ondatesetlistener() {                          @override                         public void ondateset(datepicker view, int year,                                 int month, int day) {                             // todo auto-generated method stub                             datetxtvu.settext("date: " + day + "-" + month                                     + "-" + year);                             datestr = day + "-" + month + "-" + year;                         }                      }, day, month, year);             dpd.show(); 

you passing values in wrong order. need pass values in order:

public datepickerdialog(context context, int theme, ondatesetlistener listener, int year,         int monthofyear, int dayofmonth) 

change this:

calendar mcurrentdate = calendar.getinstance();          int day   = mcurrentdate.get(calendar.day_of_month);         int month = mcurrentdate.get(calendar.month);         int year  = mcurrentdate.get(calendar.year);          datepickerdialog dpd;         dpd = new datepickerdialog(getactivity(), 0,                 new datepickerdialog.ondatesetlistener() {                      @override                     public void ondateset(datepicker view, int year,                             int month, int day) {                         // todo auto-generated method stub                         datetxtvu.settext("date: " + day + "-" + month                                 + "-" + year);                         datestr = day + "-" + month + "-" + year;                     }                  }, year, month, day);         dpd.show(); 

year comes first month , day in last.


Comments