Thursday, 15 March 2012

android - Datepicker: How to popup datepicker when click on edittext -



android - Datepicker: How to popup datepicker when click on edittext -

i want show datepicker popup window. have found examples not getting properly. have 1 edittext , want when click on edittext datepicker dialog should popup , after setting date, date should show in edittext in dd/mm/yyyy format. please provide me sample code or links.

try this:

calendar mycalendar = calendar.getinstance(); datepickerdialog.ondatesetlistener date = new datepickerdialog.ondatesetlistener() { @override public void ondateset(datepicker view, int year, int monthofyear, int dayofmonth) { // todo auto-generated method stub mycalendar.set(calendar.year, year); mycalendar.set(calendar.month, monthofyear); mycalendar.set(calendar.day_of_month, dayofmonth); updatelabel(); } }; edittext.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { // todo auto-generated method stub new datepickerdialog(classname.this, date, mycalendar .get(calendar.year), mycalendar.get(calendar.month), mycalendar.get(calendar.day_of_month)).show(); } }); private void updatelabel() { string myformat = "mm/dd/yy"; //in need set here simpledateformat sdf = new simpledateformat(myformat, locale.us); edittext.settext(sdf.format(mycalendar.gettime())); }

android

No comments:

Post a Comment