heysupratim / material-daterange-picker

A material Date Range Picker based on wdullaers MaterialDateTimePicker
Apache License 2.0
1.33k stars 266 forks source link

Make Selected date in TO tab always be greater than FROM selection #48

Open SirajShan opened 8 years ago

SirajShan commented 8 years ago

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.

faisalmohd83 commented 8 years ago

Any thought on this? any lead would be appreciated.

irinalomaka commented 7 years ago

We need to have a function to set a data in each tab.

hawkraph commented 5 years ago

@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

yasirtahir commented 4 years ago

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.

nikulvaghani commented 1 year ago

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