Ungapps
Ungapps

Reputation: 98

Android: How to set first day of week in DateRangePicker?

How to set first day of week to monday or saturday ?

I can't find method or variable to change it. Like picture example below, first day of week is monday. Thanks in advance.

enter image description here

link github DateRangePicker https://github.com/savvisingh/DateRangePicker

Thanks for the answer. I finally figure it out. You need to initialize Locale and Timezone to change first day of week. Not calendar that you have to change. Don't need to break the library code too.

new CalendarPickerView.init(date1, date1, TimeZone.getDefault(), Locale.UK, new SimpleDateFormat("MMMM, YYYY", Locale.getDefault())) //
                        .inMode(CalendarPickerView.SelectionMode.MULTIPLE)
                        .withSelectedDates(listDate); 

Upvotes: 1

Views: 1959

Answers (3)

faranjit
faranjit

Reputation: 1637

I have looked at that repository. The library creates days from 0 to 7 in a loop and gets days. See this.

The calendar here in use is created in init method in CalendarPickerView. Look at CalendarPickerView.

today = Calendar.getInstance(timeZone, locale);

I think if you change first day of week of calendar or default locale/timezone, you can do what you want.

Upvotes: 1

Viral Patel
Viral Patel

Reputation: 1316

As per you using the DateRangePicker library :

For Example:

Use this code in your project.

    // create a calendar
     Calendar cal = Calendar.getInstance();

   // set first day of the week as something else
     cal.setFirstDayOfWeek(Calendar.WEDNESDAY);

or it will not run then required for you to change in library code with create method and put above code then used it in your project.

Upvotes: 1

Xavi Jimenez
Xavi Jimenez

Reputation: 332

The first day of week is determined by your locale. Set it to something like English (UK) or German and you will have Monday as first day of week.

Then if it dosen't work you can change by code, like :

datePickerDialog.setFirstDayOfWeek(int weekStart);

If you want monday weekStart = 2

I hope it will help you!

Upvotes: 2

Related Questions