android - Avoid future dates when validating birthdates -
i'm trying birthdate in form of "mm/dd/yyyy", , want consider "future" dates invalid.
here's code far:
final calendar c = calendar.getinstance(); mday = c.get(calendar.day_of_month); mmonth = c.get(calendar.month); myear = c.get(calendar.year); //string db=bdate.gettext().tostring(); bdate.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { showdialog(date_dialog_id); } }); updatedisplay(); } private void updatedisplay() { // todo auto-generated method stub this.bdate.settext(new stringbuilder() // month 0 based add 1 .append(mday).append("-").append(mmonth + 1).append("-") .append(myear).append(" ")); } private datepickerdialog.ondatesetlistener mdatesetlistener = new datepickerdialog.ondatesetlistener() { public void ondateset(datepicker view, int monthofyear, int dayofmonth,int year) { mday = dayofmonth; mmonth = monthofyear; myear = year; if (year > myear) view.updatedate(myear,mmonth,mday); if (monthofyear > mmonth && year == myear) view.updatedate(myear, mmonth, mday); if (dayofmonth > mday && year == myear && monthofyear == mmonth) view.updatedate(mday, mmonth, myear); updatedisplay(); } }; @override protected dialog oncreatedialog(int id) { switch (id) { case date_dialog_id: return new datepickerdialog(this, mdatesetlistener,mday,mmonth,myear); } return null; }
i used textview, @ moment accepts "future" dates. how can improve validation code?
enter code herelook @ using calendar.after(calendar) method: http://developer.android.com/reference/java/util/calendar.html#after(java.lang.object)
in ondateset callback, can use returned values create new calendar object called selecteddate. then...
boolean isaftertoday = selecteddate.after(c);
Comments
Post a Comment