Answer the question
In order to leave comments, you need to log in
How to correctly set the minimum date?
I have two buttons. First departure, second arrival. Departure date has minDate = today. And the date of arrival minDate must be equal to the selected date for departure.
In onCreate():
final Calendar nextYear = Calendar.getInstance();
nextYear.add(Calendar.YEAR, 1);
Date today = new Date();
Date departs;
initButtonListeners(today, nextYear);
public void initButtonListeners(final Date today, final Calendar nextYear) {
findViewById(id.linearCalendar).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCalendarInDialog("Выберите дату вылета", R.layout.calendar_dialog_customized);
dialogView.init(today, nextYear.getTime())
.withSelectedDate(new Date(departData));
}
});
findViewById(id.linearArrive).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCalendarInDialog("Выберите дату прилета", R.layout.calendar_dialog_customized);
Date dates = null;
SimpleDateFormat format = new SimpleDateFormat("dd MMM yyyy");
try {
dates = format.parse(departData);
} catch (ParseException e) {
e.printStackTrace();
}
dialogView.init(dates, nextYear.getTime())
.withSelectedDate(new Date(arriveData));
}
}
});
}
dialogView.setOnDateSelectedListener(new CalendarPickerView.OnDateSelectedListener() {
DateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy");
@Override
public void onDateSelected(Date date) {
if(isFrom){
departData = dateFormat.format(date);
tvDepart.setText(departData);
}else{
arriveData = dateFormat.format(date);
tvArrive.setText(arriveData);
}
theDialog.dismiss();
}
@Override
public void onDateUnselected(Date date) {
}
});
java.lang.IllegalArgumentException: The string argument is null
at java.util.Date.parse(Date.java:373)
at java.util.Date.<init>(Date.java:149)
at com.tezz.MainContent.ContentActivity$2.onClick(ContentActivity.java:305)
at android.view.View.performClick(View.java:4084)
at android.view.View$PerformClick.run(View.java:16966)
at android.os.Handler.handleCallback(Handler.java:615)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4745)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question