I have two dates i.e Startdate and Enddate.I am using DatePickerDialog. Suppose my Startdate is 1-3-2014 then I want to restrict Enddate going to previous date of Startdate.
Asked
Active
Viewed 75 times
1
-
check http://stackoverflow.com/questions/16749361/how-set-maximum-date-in-datepicker-dialog-in-android – vs.thaakur Feb 28 '14 at 06:44
-
@Sandeep, try below solution and let me know whether it is working or not. – InnocentKiller Feb 28 '14 at 06:57
-
I am Glad it worked out for you. – InnocentKiller Apr 07 '14 at 09:49
1 Answers
3
It's very simple just use it like this.
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
}
or same like this also you can check
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();
}
Difference is just before
and after
keyword.
Here duedate
and assigndate
both are your Calendar
variable.

InnocentKiller
- 5,234
- 7
- 36
- 84