I am using the DatePikerDialog to publish news from my android app, this dialog is launched by a button in which the publication date is chosen, which has to be greater than or equal to the current date , if this is smaller, skip a snackbar of information.
The fact is that when the date, that is, the day coincides with the current day, sometimes the snackbar jumps (something that did not have to happen) and sometimes not, and I do not know what this may be due to. In the same code I make a TimePickerDialog jump but that in principle does not give problem. I attach the code in question:
final Calendar fEle = Calendar.getInstance();
final Calendar cal = Calendar.getInstance();
final ArrayList total = new ArrayList();
DatePickerDialog.OnDateSetListener odsl = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int i, int i1, int i2) {
final Calendar hEle = Calendar.getInstance();
hEle.set(Calendar.YEAR, i);
hEle.set(Calendar.MONTH, i1);
hEle.set(Calendar.DAY_OF_MONTH, i2);
DateFormat formato=DateFormat.getDateInstance();
total.add(formato.format(new Date(hEle.getTimeInMillis()))+" ");
if (cal.before(fEle) || cal.equals(fEle)) {
TimePickerDialog.OnTimeSetListener otsl = new TimePickerDialog.OnTimeSetListener() {
@Override
public void onTimeSet(TimePicker timePicker, int i, int i1) {
hEle.set(fEle.get(Calendar.YEAR), fEle.get(Calendar.MONTH), fEle.get(Calendar.DATE), i, i1);
if (cal.equals(fEle)) {
if (cal.getTime().after(hEle.getTime())) {
Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.errFechaEmpiece, Snackbar.LENGTH_LONG)
.show();
} else {
total.add(i + ":" + i1);
}
} else {
total.add(i + ":" + i1);
}
if(total.size()>=2) {
cambiarLaFechaDePublicacion((String) total.get(0), (String) total.get(1));
}
}
};
TimePickerDialog dialog = new TimePickerDialog(getContext(), otsl,
java.util.Calendar.getInstance().get(java.util.Calendar.getInstance().HOUR),
java.util.Calendar.getInstance().get(java.util.Calendar.getInstance().MINUTE),
true);
dialog.show();
} else {
Snackbar.make(getActivity().findViewById(android.R.id.content), R.string.errFechaEmpiece, Snackbar.LENGTH_LONG)
.show();
}
}
};
DatePickerDialog dpd = new DatePickerDialog(getActivity(), odsl,
java.util.Calendar.getInstance().get(java.util.Calendar.getInstance().YEAR),
java.util.Calendar.getInstance().get(java.util.Calendar.MONTH),
java.util.Calendar.getInstance().get(java.util.Calendar.DAY_OF_MONTH));
dpd.show();
Thanks and best regards.