android - Pass the datepicker year,day,month variables to another activity -


i want pass variables year, month, , day activity.

how can that?

button button; int year_x,month_x,day_x; static final int dialog_id = 0;   @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_main);      final calendar cal = calendar.getinstance();     year_x = cal.get(calendar.year);     month_x = cal.get(calendar.month);     day_x = cal.get(calendar.day_of_month);      showdialogonbuttonclick(); }   public void showdialogonbuttonclick(){      button = (button)findviewbyid(r.id.button);     button.setonclicklistener(             new view.onclicklistener() {                 @override                 public void onclick(view v) {                     showdialog(dialog_id);                 }             }     ); }   @override protected dialog oncreatedialog(int id){      if(id == dialog_id)         return new datepickerdialog(this,dpickerlistner,year_x,month_x,day_x);     return null; } private datepickerdialog.ondatesetlistener dpickerlistner         = new datepickerdialog.ondatesetlistener() {     @override     public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) {         year_x = year;         month_x = monthofyear + 1;         day_x = dayofmonth;         toast.maketext(mainactivity.this,year_x +"/"+ month_x+"/"+day_x,toast.length_long).show();     } }; 

this how start activity shows calendarview , datepicker

public void onbuttonclick(view view){     if(view.getid()==r.id.button2)     {         intent = new intent(mainactivity.this,calendarview.class);         startactivity(i);     } } } 

i don't have enough reputation comment that's why answering question here.

so first create pojo class hold data want pass next activity .

create object of pojo class , put in intent object created here :

intent = new intent(mainactivity.this,calendarview.class);         startactivity(i); 

i.e code should follows :

intent = new intent(mainactivity.this,calendarview.class); i.putextra("data", yourpojoobj);         startactivity(i); 

thats it. make sure pojo class implements serializable interface java.


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 -