In DatePicker
, on DataChanged
callback when I select weekends either saturday or sunday,I am programatically changing the date to upcoming monday/tuesday using view.setMinDate(expectedDay)
. During initial press 2 or 3 times, it works correctly. By Pressing 3 times consecutively or clicking any days randomly to and forth in datepicker the same day(saturday/sunday) is getting selected which should not happen, it should go to programmatically changed date. By Logic it goes to expected if case, view.setMinDate()
is called again, it is in same day instead of navigating to expected day programmatically.
tvStartDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
DatePickerDialog datePickerDialogFromDate = new DatePickerDialog(getContext(), R.style.datePickerTheme, fromDateListner, fromDateCalendar
.get(Calendar.YEAR), fromDateCalendar.get(Calendar.MONTH),
fromDateCalendar.get(Calendar.DAY_OF_MONTH)) {
@Override
public void onDateChanged(@NonNull DatePicker view, int year, int month, int dayOfMonth) {
//super.onDateChanged(view, year, month, dayOfMonth);
// Calendar newDate = Calendar.getInstance();
testCalendar.set(year, month, dayOfMonth);
Date choosenDate = testCalendar.getTime();
String dayOfTheWeek = new SimpleDateFormat("EEEE").format(choosenDate);
Log.v("Selected Day of Week >>>>", dayOfTheWeek);
try {
if (dayOfTheWeek.equalsIgnoreCase("THURSDAY")) {
Log.v("Day of Week >>>>THURSDAY", "Should be Monday");
view.setMinDate(testCalendar.getTimeInMillis() + 4 * 24 * 60 * 60 * 1000);
} else if (dayOfTheWeek.equalsIgnoreCase("FRIDAY")) {
Log.v("Day of Week >>>>FRIDAY", "Should be Tuesday");
view.setMinDate(testCalendar.getTimeInMillis() + 4 * 24 * 60 * 60 * 1000);
} else if (dayOfTheWeek.equalsIgnoreCase("SATURDAY")) {
Log.v("Day of Week >>>>SATURDAY", "Should be Tuesday");
view.setMinDate(testCalendar.getTimeInMillis() + 3 * 24 * 60 * 60 * 1000);
} else if (dayOfTheWeek.equalsIgnoreCase("SUNDAY")) {
Log.v("Day of Week >>>>SUNDAY", "Should be Tuesday");
view.setMinDate(testCalendar.getTimeInMillis() + 2 * 24 * 60 * 60 * 1000);
} else {
view.setMinDate(testCalendar.getTimeInMillis());
}
view.invalidate();
} catch (Exception ex) {
Log.v("Exception in getting Day of Week>>", ex.getMessage());
}
}
};
datePickerDialogFromDate.getDatePicker().setMinDate(System.currentTimeMillis() + Integer.parseInt(mReservationIntvl) * 24 * 60 * 60 * 1000);
datePickerDialogFromDate.show();
});
Is it this my code issue or any there workaround for it?I tried to get date from datepicker using datepicker.getMin()
public void updateDaysInDatePickerView(final DatePicker datePickerView, int noOfDays, Date date) {
try {
long NO_OF_DAYS_IN_MILLISECS = noOfDays * 24 * 60 * 60 * 1000;
long pushed_date = NO_OF_DAYS_IN_MILLISECS + date.getTime();
datePickerView.setMinDate(pushed_date);
getActivity().runOnUiThread(new Runnable() {
@Override
public void run() {
datePickerView.invalidate();
Calendar takenCalendar = Calendar.getInstance();
takenCalendar.setTimeInMillis(datePickerView.getMinDate());
Log.v("Day is>>>", "" + takenCalendar.get(Calendar.DATE));
Log.v("Month is>>>", "" + takenCalendar.get(Calendar.MONTH));
Log.v("Year is>>>", "" + takenCalendar.get(Calendar.YEAR));
}
});
} catch (Exception e) {
Log.d("Exception is this updateDaysInDatePickerView>>>", e.getMessage());
}
}
Date is showing as Monday not in UI is not getting updated,i tried invalidating view,it is not updating.
I tried in redmi note 5 pro(8.0),it is working as expected,In Samsung S6 edge,and A2Max,(7.1 & 7.1.1)we are getting this issue,I am not sure this issue is device as specific or OS specific not sure.