material-daterange-picker
material-daterange-picker copied to clipboard
Make Selected date in TO tab always be greater than FROM selection
If i select a future date in the From tab and i clicked on To tab. It is still showing current date as selected. The To tab value should be same or latter than The value selected in from tab.
Any thought on this? any lead would be appreciated.
We need to have a function to set a data in each tab.
@Override public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth, int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) { if(yearEnd < year){ ShowMessage("Please select current or future year"); }else if(monthOfYearEnd < monthOfYear){ ShowMessage("Please select current or future month"); }else if(dayOfMonthEnd < dayOfMonth){ ShowMessage("Please select current or future day"); }else { String date = "You picked the following date: From- "+dayOfMonth+"/"+(++monthOfYear)+"/"+year+" To "+dayOfMonthEnd+"/"+(++monthOfYearEnd)+"/"+yearEnd; ShowMessage(date); }
}
NB: Please watch the month pre-increments. i.e You should only increment once otherwise the month won't be correct
I think @hawkraph is right. You can put validation once the User click OK button in the onDateSet method. Within this callback method, you can put any type of validation based on your business.
@OverRide public void onDateSet(DatePickerDialog view, int year, int monthOfYear, int dayOfMonth, int yearEnd, int monthOfYearEnd, int dayOfMonthEnd) {
SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); try { Date fromDate = sdf.parse(dayOfMonth + "/" + monthOfYear + "/" + year); Date toDate = sdf.parse(dayOfMonthEnd + "/" + monthOfYearEnd + "/" + yearEnd); if (fromDate.after(toDate)) { Toast.makeText(this, "To Date must be after the From Date!", Toast.LENGTH_SHORT).show(); return; } } catch (ParseException e) { throw new RuntimeException(e); } }