0
我試圖以「MM/DD/YYYY」的形式出生,並且我想考慮「將來」日期無效。避免驗證生日的將來日期
這裏是我到目前爲止的代碼:
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 is 0 based so 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;
}
我用的TextView,但此刻它接受「未來」的日期。我如何改進我的驗證碼?
請問你能解釋一下我是不是要把那段代碼謝謝 – sonam 2013-04-05 19:10:20