2014-02-28 19 views
1

我有兩個日期,即Startdate和Enddate.I使用DatePickerDialog。 假設我的Startdate是1-3-2014,那麼我想限制Enddate去往Startdate的前一個日期。限制Endate轉到StartDate的前一日期

+0

檢查http://stackoverflow.com/questions/16749361/how-set-maximum-date-in-datepicker-dialog-in-android –

+0

@Sandeep,嘗試下面的解決方案,讓我知道它是否工作與否。 – InnocentKiller

+0

@ InnocentKiller,它正在工作。謝謝 – Sandeep

回答

3

這很簡單,就像這樣使用它。

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(); 
} 

不同的只是beforeafter關鍵字。

這裏duedateassigndate都是你的Calendar變量。

相關問題