datepicker - The day name showing incorrect value, next day or previous day in Android -


public class main extends activity {         protected static final int dialog = 0;     private int day;     private int month;     private int year;     button mbt;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         mbt = (button) findviewbyid(r.id.button1);         mbt.setonclicklistener(new onclicklistener() {         public void onclick(view arg0) {             showdialog(dialog);         }         });     }      private void  updatedisplay() {         string day = (dateformat.format("eeeeee", new date(year, month, day))).tostring();         toast.maketext(main.this, day, toast.length_long).show();     }      private datepickerdialog.ondatesetlistener      mdatesetlistener = new datepickerdialog.ondatesetlistener() {         @override         public void ondateset(datepicker arg0, int year, int monthofyear, int dayofmonth) {             year = year;             month = monthofyear;             day = dayofmonth;             updatedisplay();         }     };      protected dialog oncreatedialog(int id){         switch(id) {             case dialog:                 return new datepickerdialog(this ,mdatesetlistener ,year , month , day);         }         return null;     } } 

when select date, android modifies date own timezone, should create calendar type variable using, calendar.getinstance(timezone.getdefault()) , issue calendar.set(int year, int month, int day). http://developer.android.com/reference/java/util/calendar.html if unsure something! :)

correct code be:

public class main extends activity {     protected static final int dialog = 0; private int day; private calendar c; private int month; private int year;      button mbt;      @override     protected void oncreate(bundle savedinstancestate) {         super.oncreate(savedinstancestate);         setcontentview(r.layout.main);         c = new calendar(timezone.getdefault());         mbt = (button) findviewbyid(r.id.button1);         mbt.setonclicklistener(new onclicklistener() {         public void onclick(view arg0) {             showdialog(dialog);         }         });     }      private void  updatedisplay() {         string day = c.getdisplayname(calendar.day_of_week, calendar.long, locale.getdefault());         toast.maketext(main.this, day, toast.length_long).show();     }      private datepickerdialog.ondatesetlistener      mdatesetlistener = new datepickerdialog.ondatesetlistener() {         @override         public void ondateset(datepicker arg0, int year, int monthofyear, int dayofmonth) {             year = year;             month = monthofyear;             day = dayofmonth;             c.set(year, month, day);             updatedisplay();         }     };      protected dialog oncreatedialog(int id){         switch(id) {             case dialog:                 return new datepickerdialog(this ,mdatesetlistener ,year , month , day);         }         return null;     } } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -