In my activity, a user can select a date via datepicker. I what to ensure, that the selected date does not lie in the futur.
What it got so far:
private String textStart="";
private String textEnd="";
private String setToday="";
calendar = Calendar.getInstance();
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
setToday = day+"/"+(month+1)+"/"+year;
when i pick date from datepicker
private DatePickerDialog.OnDateSetListener myDateListener
= new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) {
// TODO Auto-generated method stub
// arg1 = year
// arg2 = month
// arg3 = day
showDateStart(arg1, arg2 + 1, arg3);
}
call method showDateStart for check scope of date
private void showDateStart(int year, int month, int day) {
textDateStart.setText(new StringBuilder().append(day).append("/")
.append(month).append("/").append(year));
startStamp=true;
textStart = day+"/"+month+"/"+year;
if(textStart.compareTo(setToday)>0){
textStart = setToday;
Toast.makeText(getActivity(), "out of scope::"+setToday,
Toast.LENGTH_LONG).show();
textDateStart.setText(setToday);
}
}
but not work if i pick 1/1/2016 because today is 22/2/2015 value of textStart not more than settoday
sorry for my mistake it first question.
As a bonus: Is it possible to restrict the datepicker to only display dates up to today?