1
我有兩個日期,即Startdate和Enddate.I使用DatePickerDialog。 假設我的Startdate是1-3-2014,那麼我想限制Enddate去往Startdate的前一個日期。限制Endate轉到StartDate的前一日期
我有兩個日期,即Startdate和Enddate.I使用DatePickerDialog。 假設我的Startdate是1-3-2014,那麼我想限制Enddate去往Startdate的前一個日期。限制Endate轉到StartDate的前一日期
這很簡單,就像這樣使用它。
if (DueDate.before(AssignDate))
{
AlertDialog.Builder alertDialogBuilderDate = new AlertDialog.Builder(
Assignment_Create_Ext_DB.this);
alertDialogBuilderDate.setTitle("Date assigning issue");
alertDialogBuilderDate
.setMessage(
"Due date can not be equal or less then the Assign date")
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog, int id) {
dialog.cancel();
}
});
alertDialogBuilderDate.show();
}
else
{
// use your coding
}
或相同這樣也可以檢查
if (DueDate.after(AssignDate))
{
// use your coding
}
else
{
AlertDialog.Builder alertDialogBuilderDate = new AlertDialog.Builder(
Assignment_Create_Ext_DB.this);
alertDialogBuilderDate.setTitle("Date assigning issue");
alertDialogBuilderDate
.setMessage(
"Due date can not be equal or less then the Assign date")
.setCancelable(false)
.setPositiveButton("Ok",
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog, int id) {
dialog.cancel();
}
});
alertDialogBuilderDate.show();
}
不同的只是before
和after
關鍵字。
這裏duedate
和assigndate
都是你的Calendar
變量。
檢查http://stackoverflow.com/questions/16749361/how-set-maximum-date-in-datepicker-dialog-in-android –
@Sandeep,嘗試下面的解決方案,讓我知道它是否工作與否。 – InnocentKiller
@ InnocentKiller,它正在工作。謝謝 – Sandeep