java - Time picker stops working after date picker is added -


i'm building app displays date picker , time picker on click of 2 seperate buttons. first added in time picker , working fine, proceeded add date picker works fine. problem here being when added in date picker, casused time picker stop working. know both work , i'm 90% sure because of structure of code being i'm new android , java development can't work out i'm going wrong. appreciated. thanks

code below:

package com.cam.datetime; import java.util.calendar;  import android.app.activity; import android.app.alertdialog; import android.app.datepickerdialog; import android.app.dialog; import android.app.timepickerdialog; import android.app.timepickerdialog.ontimesetlistener; import android.content.dialoginterface; import android.content.intent; import android.content.pm.activityinfo; import android.os.bundle; import android.telephony.smsmanager; import android.view.view; import android.view.view.onclicklistener; import android.widget.button; import android.widget.datepicker; import android.widget.edittext; import android.widget.textview; import android.widget.timepicker;  public class settingsscreen extends activity {   private textview tvdisplaytime; private timepicker timepicker1; private button btnchangetime;  private int hour; private int minute;  static final int time_dialog_id = 999;      button change_date_but;     textview display_txt;     public static final int date_dialog_id = 1;  // date private int myear; private int mmonth; private int mday;  @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.screen_settings); this.setrequestedorientation(activityinfo.screen_orientation_portrait);    setcurrenttimeonview(); addlisteneronbutton();   final edittext inputtxt1 = (edittext) findviewbyid(r.id.conphonenum);     button savebtn1 = (button) findviewbyid(r.id.btnsave1);  change_date_but = (button) findviewbyid(r.id.change_button_id); display_txt = (textview) findviewbyid(r.id.display_id); change_date_but = (button) findviewbyid(r.id.change_button_id); change_date_but.setonclicklistener(new onclicklistener() {      @override     public void onclick(view v) {     datepickerdialog dpd = new datepickerdialog(     settingsscreen.this, mdatesetlistener, myear, mmonth, mday);     dpd.show();     }      final calendar c = calendar.getinstance();{         myear = c.get(calendar.year);         mmonth = c.get(calendar.month);         mday = c.get(calendar.day_of_month);}         void updatedisplay1() {         }         });   savebtn1.setonclicklistener(new view.onclicklistener() {    @override    public void onclick(view view) {       string phonenum1 = inputtxt1.gettext().tostring();       savenum1(phonenum1);        //intent passintent = new intent();       //passintent.putextra("phonenum", phonenum1);     }    });   button homebutton = (button) findviewbyid(r.id.btnhome); homebutton.setonclicklistener(new view.onclicklistener(){     public void onclick(view view) {         starthome();     } });   button rettimebtn = (button) findviewbyid(r.id.btnrettime); rettimebtn.setonclicklistener(new onclicklistener() {       @override       public void onclick(view view) {         //returntime();        }     });  }             //display current time public void setcurrenttimeonview() {      tvdisplaytime = (textview) findviewbyid(r.id.tvtime);     timepicker1 = (timepicker) findviewbyid(r.id.timepicker1);      final calendar c = calendar.getinstance();     hour = c.get(calendar.hour_of_day);     minute = c.get(calendar.minute);      // set current time textview     tvdisplaytime.settext(              new stringbuilder().append(pad(hour))                                 .append(":").append(pad(minute)));      // set current time timepicker     timepicker1.setcurrenthour(hour);     timepicker1.setcurrentminute(minute);  }    private object pad(int minute2) {     // todo auto-generated method stub     return null; }    public void addlisteneronbutton() {      btnchangetime = (button) findviewbyid(r.id.btnchangetime);      btnchangetime.setonclicklistener(new onclicklistener() {          @suppresswarnings("deprecation")         @override         public void onclick(view v) {              showdialog(time_dialog_id);          }      });    }     @override protected dialog oncreatedialog(int id) {     switch (id) {     case time_dialog_id:          ontimesetlistener timepickerlistener = null;         // set time picker current time         return new timepickerdialog(this,                                   timepickerlistener, hour, minute,false);      }     return null; }      @override @deprecated protected void onpreparedialog(int id, dialog dialog) { // todo auto-generated method stub super.onpreparedialog(id, dialog); ((datepickerdialog) dialog).updatedate(myear, mmonth, mday); }  private datepickerdialog.ondatesetlistener mdatesetlistener = new         datepickerdialog.ondatesetlistener() {          public void ondateset(datepicker view, int year, int monthofyear,          int dayofmonth) {         myear = year;         mmonth = monthofyear;         mday = dayofmonth;         updatedisplay();          }         };            private void updatedisplay() {             // todo auto-generated method stub             display_txt.settext(new stringbuilder()             // month 0 based add 1             .append(mmonth + 1).append("-").append(mday).append("-")             .append(myear));              }    public void starthome() {    intent launchhome = new intent();    launchhome.setflags(intent.flag_activity_reorder_to_front);    launchhome.setclassname(this,"com.cam.datetime.mainactivity");    startactivity(launchhome);      }   public void savenum1(string phonenum1) {  alertdialog.builder dlgalert  = new alertdialog.builder(this);  dlgalert.setmessage("saved " + phonenum1); dlgalert.setpositivebutton("ok", null); dlgalert.setcancelable(true);  dlgalert.setpositivebutton("ok",     new dialoginterface.onclicklistener() {         public void onclick(dialoginterface dialog, int which) {           //dismiss dialog           }     });     dlgalert.create().show(); }      public void returntime(){  smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage("", null, "#tu?", null, null);  } } 

give try:

    import java.util.calendar;      import android.app.activity;     import android.app.alertdialog;     import android.app.datepickerdialog;     import android.app.datepickerdialog.ondatesetlistener;     import android.app.dialog;     import android.app.timepickerdialog;     import android.app.timepickerdialog.ontimesetlistener;     import android.content.dialoginterface;     import android.content.intent;     import android.content.pm.activityinfo;     import android.os.bundle;     import android.telephony.smsmanager;     import android.view.view;     import android.view.view.onclicklistener;     import android.widget.button;     import android.widget.edittext;     import android.widget.textview;     import android.widget.timepicker;      public class settingsscreen extends activity {   private textview tvdisplaytime; private timepicker timepicker1; private button btnchangetime;  private int hour; private int minute;  static final int time_dialog_id = 999;  button change_date_but; textview display_txt; public static final int date_dialog_id = 1;  // date private int myear; private int mmonth; private int mday;      @override     protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.screen_settings); this.setrequestedorientation(activityinfo.screen_orientation_portrait);  final edittext inputtxt1 = (edittext) findviewbyid(r.id.conphonenum);     button savebtn1 = (button) findviewbyid(r.id.btnsave1);  setcurrenttimeonview(); //addlisteneronbutton(); change_date_but = (button) findviewbyid(r.id.change_button_id); display_txt = (textview) findviewbyid(r.id.display_id); change_date_but = (button) findviewbyid(r.id.change_button_id); button rettimebtn = (button) findviewbyid(r.id.btnrettime); button homebutton = (button) findviewbyid(r.id.btnhome); btnchangetime = (button) findviewbyid(r.id.btnchangetime);    change_date_but.setonclicklistener(new onclicklistener() {      @override     public void onclick(view v) {     ondatesetlistener mdatesetlistener = null;     datepickerdialog dpd = new datepickerdialog(     settingsscreen.this, mdatesetlistener, myear, mmonth, mday);     dpd.show();     }      final calendar c = calendar.getinstance();{         myear = c.get(calendar.year);         mmonth = c.get(calendar.month);         mday = c.get(calendar.day_of_month);}         /*void updatedisplay1() {         }*/         });           savebtn1.setonclicklistener(new view.onclicklistener() {            @override            public void onclick(view view) {               string phonenum1 = inputtxt1.gettext().tostring();               savenum1(phonenum1);        //intent passintent = new intent();       //passintent.putextra("phonenum", phonenum1);          }         });    homebutton.setonclicklistener(new view.onclicklistener(){     public void onclick(view view) {         starthome();         }         });    rettimebtn.setonclicklistener(new onclicklistener()         {   @override   public void onclick(view view) {     //returntime();            }         });           btnchangetime.setonclicklistener(new onclicklistener() {          @suppresswarnings("deprecation")         @override         public void onclick(view v) {              showdialog(time_dialog_id);         }     });        }                    //display current time public void setcurrenttimeonview() {      tvdisplaytime = (textview) findviewbyid(r.id.tvtime);     timepicker1 = (timepicker) findviewbyid(r.id.timepicker1);      final calendar c = calendar.getinstance();     hour = c.get(calendar.hour_of_day);     minute = c.get(calendar.minute);      // set current time textview     tvdisplaytime.settext(            new stringbuilder().append(pad(hour))                               .append(":").append(pad(minute)));      // set current time timepicker     timepicker1.setcurrenthour(hour);     timepicker1.setcurrentminute(minute);  }    private object pad(int minute2) {     // todo auto-generated method stub     return null; }   @override protected dialog oncreatedialog(int id) {     switch (id) {     case time_dialog_id:          ontimesetlistener timepickerlistener = null;         // set time picker current time         return new timepickerdialog(this,                                   timepickerlistener, hour, minute,false);      }     return null; }        /*  @override @deprecated protected void onpreparedialog(int id, dialog dialog) { // todo auto-generated method stub super.onpreparedialog(id, dialog); ((datepickerdialog) dialog).updatedate(myear, mmonth, mday); }  private datepickerdialog.ondatesetlistener mdatesetlistener = new         datepickerdialog.ondatesetlistener() {          public void ondateset(datepicker view, int year, int monthofyear,          int dayofmonth) {         myear = year;         mmonth = monthofyear;         mday = dayofmonth;         updatedisplay();          }         };            private void updatedisplay() {             // todo auto-generated method stub             display_txt.settext(new stringbuilder()             // month 0 based add 1             .append(mmonth + 1).append("-").append(mday).append("-")             .append(myear));              }         */      public void starthome() {    intent launchhome = new intent();    launchhome.setflags(intent.flag_activity_reorder_to_front);    launchhome.setclassname(this,"com.becatech.gsmzonecontroller.mainactivity");    startactivity(launchhome);      }       public void savenum1(string phonenum1) {  alertdialog.builder dlgalert  = new alertdialog.builder(this);  dlgalert.setmessage("saved " + phonenum1); dlgalert.setpositivebutton("ok", null); dlgalert.setcancelable(true);  dlgalert.setpositivebutton("ok",     new dialoginterface.onclicklistener() {         public void onclick(dialoginterface dialog, int which) {           //dismiss dialog           }     });     dlgalert.create().show(); }      public void returntime(){  smsmanager smsmanager = smsmanager.getdefault(); smsmanager.sendtextmessage("", null, "#tu?", null, null);  }     } 

Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -