I want to set a date limit so that the user cannot select a date more than this, for example, if today is January 1, then the User will not be able to select more than 7 dates, I mean that he can not select January 9, I also want so that he does not choose the month and year. Therefore, I set a limit to set its task in one week.
what I have done so far shows a date selection snippet and sets the current date in it. The code in my main action is as follows:
etSelectDate.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
DialogFragment datePickerFragment = new DatePickerFragment() {
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
Log.d("Date Change", "onDateSet");
Calendar c = Calendar.getInstance();
c.set(year, month, day);
DateFormat df = DateFormat.getDateInstance();
etSelectDate.setText(df.format(c.getTime()));
}
};
datePickerFragment.show(MainActivity.this.getSupportFragmentManager(), "datePicker");
}
});
and the date picker slice class is as follows:
public static class DatePickerFragment extends DialogFragment implements DatePickerDialog.OnDateSetListener{
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
final Calendar c = Calendar.getInstance();
int year = c.get(Calendar.YEAR);
int month = c.get(Calendar.MONTH);
int day = c.get(Calendar.DAY_OF_MONTH);
return new DatePickerDialog(getActivity(), this, year, month, day);
}
@Override
public void onDateSet(DatePicker view, int year, int month, int day) {
}
}
, , , . , , , , Android.
, , ,
, , , 7 , . , :
pickerDialog.getDatePicker().setMaxDate(new Date().getTime());
, 7 , Date? ,