Basically I am making an appointment application. So I am showing days in a list, when user select any day then the datepicker pops up and shows only respective day date enabled 3,4 weeks. For example, if I select Monday then all the Mondays of this month enabled. 7, 14, 21, 28
Asked
Active
Viewed 2,649 times
3
-
1you need to create datepicker of your own or find some library that allowed to strict date and apply date range – Iqbal Rizky Apr 05 '20 at 21:39
-
You may have a look at [here](https://stackoverflow.com/questions/35599203/disable-specific-dates-of-day-in-android-date-picker) – Zain Apr 05 '20 at 23:22
-
you have to visit. https://stackoverflow.com/questions/54440903/datepicker-only-select-mondays – Muhammad Ali Apr 05 '20 at 23:28
3 Answers
0
when you describe onPickerListener
something like this
DatePickerDialog.OnDateSetListener d=new DatePickerDialog.OnDateSetListener() {
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
dateAndTime.set(Calendar.YEAR, year);
dateAndTime.set(Calendar.MONTH, monthOfYear);
dateAndTime.set(Calendar.DAY_OF_MONTH, dayOfMonth);
setInitialDateTime();
}
};
describe and process your special days inside onDateSet
imho

Kirguduck
- 748
- 1
- 9
- 20
-
-
try another way. i think it is easier https://learntodroid.com/how-to-disable-dates-in-a-datepicker-for-android/ – Kirguduck Apr 05 '20 at 21:22
-
or even here https://stackoverflow.com/questions/53454711/how-do-you-disable-certain-days-on-a-datepicker-android – Kirguduck Apr 05 '20 at 21:28
-
0
You can use MaterialDateTimeOPicker
Pass values in this list that are the acceptable dates for the picker.
Calendar now = Calendar.getInstance();
DatePickerDialog datePicker = DatePickerDialog.newInstance(
MainActivity.this,
now.get(Calendar.YEAR), // Initial year selection
now.get(Calendar.MONTH), // Initial month selection
now.get(Calendar.DAY_OF_MONTH) // Inital day selection
);
datePicker.setSelectableDays(Calendar[] days)

Amitoz singh
- 144
- 1
- 7
0
Yesterday, I posted a question asking How can I enable only specific dates in DatePicker Android. Like whenever user click on specific day only those respective dates will available in DatePicker?. I have solved it, which I will share here:
Here are the screenshots that when user click on Monday then DatePicker pops up and enable only Mondays from that day.
code
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Day day = days.get(position);
switch (day.getDay()){
case "Monday":
appDay = 2;
break;
case "Tuesday":
appDay = 3;
break;
case "Wednesday":
appDay = 4;
break;
case "Thursday":
appDay = 5;
break;
case "Friday":
appDay = 6;
break;
case "Saturday":
appDay = 7;
break;
case "Sunday":
appDay = 1;
break;
default:
appDay = 0;
break;
}
datePickerDialog = DatePickerDialog.newInstance(DayListFragment.this,Year, Month, Day);
datePickerDialog.setThemeDark(false);
datePickerDialog.setTitle("Select Appointment Date");
Calendar calendar1 = Calendar.getInstance();
int today = calendar1.get(Calendar.DAY_OF_WEEK);
if ( appDay == today)
{
int update = 0;
for (int i = 0; i < calendars.length; i++)
{
final Calendar calendar2 = Calendar.getInstance();
calendar2.get(Calendar.DAY_OF_WEEK);
calendar2.add(Calendar.DATE, update);
calendars[i] = calendar2;
update += 7;
}
}
else if ( appDay > today)
{
int for1 = appDay - today;
for (int i = 0; i < calendars.length; i++)
{
final Calendar calendar2 = Calendar.getInstance();
calendar2.get(Calendar.DAY_OF_WEEK);
calendar2.add(Calendar.DATE, for1);
calendars[i] = calendar2;
for1 += 7;
}
}
else if ( appDay < today)
{
int for2 = (7-today)+appDay;
for (int i = 0; i < calendars.length; i++)
{
final Calendar calendar2 = Calendar.getInstance();
calendar2.get(Calendar.DAY_OF_WEEK);
calendar2.add(Calendar.DATE, for2);
calendars[i] = calendar2;
for2 += 7;
}
}
datePickerDialog.setSelectableDays(calendars);
datePickerDialog.show(getFragmentManager(),"DatePickerDialog");
}

halfer
- 19,824
- 17
- 99
- 186

Azhar Bhatti
- 91
- 1
- 3
- 14
-
2You could have simplified this snippet to ```datePickerDialog.setSelectableDays(calendars)```, the rest of the code doesn't answer the question. The problem is that native ```DatePickerDialog``` doesn't have such method. Probably, you use some library and you should have mentioned this. – Pavlo28 Nov 19 '20 at 10:03
-
After searching several days, able to find this comment. Helped a lot. If the developer(s) could incorporate examples for each of the feature, it help a lot for novice persons. Thank you. – Sriram Nadiminti Jun 26 '22 at 06:44