How to set a date in DatePicker - android

I want DatePicker shows a specific date when opened, unfortunately seems I can set only the date limits with setMinDate and setMaxDate.
Is there a way to set a date without block the selection with date limits?

DatePicker date = new DatePicker(context);
date.init(year, month, day, null);
where year, month and day are ints. Here is an explanation about init

Related

Set Date range from a specific date instead of month in CalendarView

https://github.com/kizitonwose/CalendarView
I have been using this library for setting up an horizontal calendar view. In this library they set Date range like this:-
val currentMonth = YearMonth.now()
binding.mainSingleRowCalendar.setup(
currentMonth,
currentMonth.plusMonths(2),
DayOfWeek.values().random()
)
Here the month is used to set the date range. i need it to be a specific date. Is there any work around?
My actual requirement is to show past 30 days from current date.
of(int year, int month) method
Obtains an instance of YearMonth from a year and month.
YearMonth.of(2021,9) // Sample

CalendarView show minimum date as today

I want to show calendarView that will set the minimum date as today for booking purposes. But in my code it will show the whole month and here I can book the previous date. So, I need a solution that will show dates available from today and can not select previous days.
How can I do this?
My code:
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DATE,Calendar.getInstance().getActualMinimum(Calendar.DATE));
long date = calendar.getTime().getTime();
calendar_view.setMinDate(date);
Here is a solution. You need to set current date to the calendar minimum date.
Calendar calendar = Calendar.getInstance();
mCalendarView.setMinDate(calendar.getTimeInMillis());

Android: DatePicker shows wrong day order after min date setting

Basically, we want to let user schedule a day in future from now. Here is code:
DatePicker date_picker = (DatePicker) findViewById(R.id.date_picker);
date_picker.setMinDate(System.currentTimeMillis());
// other settings
First, it shows current day: 04/Aug/2017, but when scrolling month, something strange happens:
Try this
By this user can select the minimum date is current date
DatePicker date_picker = (DatePicker) findViewById(R.id.date_picker);
date_picker.setMinDate(System.currentTimeMillis() - 1000);

Not to show the date before Present date Android DatePickerDialog

Is there a way to not to show the dates/months before present date instead of disabling the dates in Android.
Totally agree with above answer :-
Calendar c = Calendar.getInstance();
c.set(2000,01,01);
datePicker.setMinDate(c.getTime().getTime());
Using above lines datepickerdialog is not showing prevous date anymore with your datepicker dialog.

change date format in datepicker dialog android

I have edit text field and I have a method that handles onclick event on edit field and show up a date picker dialog. However I want to change date format in the dialog . It shows Aug 31 2014, I like to show 31 08 2014. Is it possible?
This question has been answered elsewhere on the site, here for example. Basically the datepicker dialog shows up in the preferred format of the end user, so if they have their phone or emulator set to mm/dd/yyyy it will show up like that, if you want it to come up dd/mm/yyyy while you are testing it make sure your emulator is set up with that as the preferred date format.
In DatePickerDialog.OnDateSetListener you will get onDateSet method where you can get
int year = selectedYear;
int month = selectedMonth;
int day = selectedDay;
dateCalendar.set(Calendar.YEAR, year);
dateCalendar.set(Calendar.MONTH, month);
dateCalendar.set(Calendar.DAY_OF_MONTH, day);
String monthname = new SimpleDateFormat("MMM").format(dateCalendar.getTime());
in SimpleDateFormat you can change date format as you want

Categories

Resources