【发布时间】:2012-02-29 06:08:30
【问题描述】:
当用户在日期选择器中选择过去的日期时,我想这样做,它不应该接受昨天的日期。我的应用程序将提示消息通知用户不能选择小于当前日期。请指导我吗?...谢谢
mDateDisplay = (TextView) findViewById(R.id.dateDisplay);
Button pickDate_btn = (Button) findViewById(R.id.pickDate);
pickDate_btn.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
showDialog(DATE_DIALOG_ID);
}
});
final Calendar now = Calendar.getInstance();
mYear = now.get(Calendar.YEAR);
mMonth = now.get(Calendar.MONTH);
mDay = now.get(Calendar.DAY_OF_MONTH);
updateDisplay();
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this,
mDateSetListener,
mYear, mMonth, mDay);
}
return null;
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
switch (id) {
case DATE_DIALOG_ID:
((DatePickerDialog) dialog).updateDate(mYear, mMonth, mDay);
break;
}
}
private void updateDisplay() {
mDateDisplay.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() {
@Override
public void onDateSet(DatePicker view, int year,int monthOfYear, int dayOfMonth) {
// TODO Auto-generated method stub
mYear = year;
mMonth = monthOfYear;
mDay = dayOfMonth;
updateDisplay();
//should add code here?
}
};
【问题讨论】:
标签: android