How to restrict future date in android dialog API 5.0 -
in android version 5.0 date picker dialogue if restrict future date using below code.
public class datepicker extends dialogfragment implements datepickerdialog.ondatesetlistener { textview datetext; public datepicker(final textview datetext) { this.datetext = datetext; } @override public dialog oncreatedialog(final bundle savedinstancestate) { int year = 0, month = 0, day = 0; final calendar c = calendar.getinstance(); year = c.get(calendar.year); month = c.get(calendar.month); day = c.get(calendar.day_of_month); datepickerdialog datepicker = new datepickerdialog(getactivity(), this, year, month, day); datepicker.getdatepicker().setmaxdate(system.currenttimemillis()); return datepicker; } @override public void ondateset(final android.widget.datepicker view, final int year, final int monthofyear, final int dayofmonth) { final string dateformat = "yyyy/mm/dd"; final simpledateformat form = new simpledateformat("yyyy-mm-dd"); date date = null; try { date = form.parse(year + "-" + (monthofyear + 1) + "-" + dayofmonth); } catch (final parseexception e) { log.d("datepicker", e.getmessage()); } final simpledateformat postformater = new simpledateformat(dateformat); final string formatteddate = postformater.format(date); datetext.settext(formatteddate); }
}
future date's text colour changed grey able pick date. how restrict date selection future date in android 5.0.
Comments
Post a Comment