android - Last selected date is not getting in datepicker dialog -
in app have 1 datepicker,i able select , set selected date in textview,but issue if again click on textview open datepicker dailog,it shows current date instead of last selected date..so issue?
public class mainactivity extends activity { private textview date_dropdown; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); date_dropdown=(textview)findviewbyid(r.id.shows_dt); calendar calendar = calendar.getinstance(); date_dropdown.settext(calendar.get(calendar.day_of_month) + "-" + (calendar.get(calendar.month) + 1) + "-" + calendar.get(calendar.year)); date_dropdown.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { showdatepickerdialog(); } }); } public void showdatepickerdialog() { system.out.println("show date picke dilg "); system.out.println("show date picke dilg"); dialogfragment newfragment1 = new selectdatefragment(); newfragment1.show(getfragmentmanager(), "datepicker"); } public class selectdatefragment extends dialogfragment implements datepickerdialog.ondatesetlistener { @override public dialog oncreatedialog(bundle savedinstancestate) { final calendar calendar = calendar.getinstance(); int yy = calendar.get(calendar.year); int mm = calendar.get(calendar.month); int dd = calendar.get(calendar.day_of_month); return new datepickerdialog(getactivity(), this, yy, mm, dd); } public void ondateset(datepicker view, int yy, int mm, int dd) { populatesetdate(yy, mm + 1, dd); } public void populatesetdate(int year, int month, int day) { date_dropdown.settext(day + "-" + month + "-" + year); } }
below line have given current date, current date only.
date_dropdown.settext(calendar.get(calendar.day_of_month) + "-" + (calendar.get(calendar.month) + 1) + "-" + calendar.get(calendar.year));
save selected date in shared preference show in textview
Comments
Post a Comment