Not to show the date before Present date Android DatePickerDialog - android

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.

Related

How to get only month and year picker in Android calendar?

I'm using DatePickerDialog with AlertDIalog.THEME_HOLO_LIGHT (in this case I'm getting the desired views) . The problem is , it only works with Android O and above .For < Android O I'm forced to use DatePickerDialog without the AlertDIalog.THEME_HOLO_LIGHT , here I am unable to get a calendar with only month and year.
use this library
Date Picker
then build your date picker like this
new SingleDateAndTimePickerDialog.Builder(this)
.bottomSheet()
.curved()
.displayMinutes(false)
.displayHours(false)
.displayDays(false)
.displayMonth(true)
.displayYears(true)
.displayDaysOfMonth(false)
.display();

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());

Date is shown twice if setMaxDate is used on DatePickerDialog

When setting the maximum date on a date picker dialog like this:
DatePickerDialog dialog = new DatePickerDialog(this, listener, year, month, day);
dialog.getDatePicker().setMaxDate(new Date().getTime());
The date is shown normally, but also a second time at the top of the dialog. I've seen that many people have encountered this bug but I didn't find a solution.
You can also see it on this image from another user
Is there any way to prevent or solve this, besides using reflection?
I solved the bug by calling dialog.setTitle(null) every time a maximum date is set.
I posted this issue here: https://issuetracker.google.com/72284741

How to get time time picker from time picker dialog?

On back press in date picker and time picker dialog there is known issue in android jellybean and higher that onDateSet() and onTimeSet() methods are called. To overcome this issue i have found a solution for date picker here(https://stackoverflow.com/a/11493752) but the java file(mentioned in 1st point) provided in it has getDatePicker() method for getting date picker from date picker dialog. But there is no such getTimePicker() method for getting time picker. Can anyone help me with this so that time picker also behaves similar to date picker.
Thanks in advance.
I did a lot of digging and have found a solution to this and it works fine in my project. In time picker we don't need to get time picker from time picker dialog as it does for date picker by getDatePicker() method. Just create a new Time picker and pass that only to listener in onTimeSet().
final TimePicker tp= new TimePicker(getActivity());
Calendar cal=Calendar.getInstance();
final int hour = cal.get(Calendar.HOUR_OF_DAY);
final int minute = cal.get(Calendar.MINUTE);
picker.onTimeChanged(tp, hour, minute);

Fixing a certain year in datepicker in android

I want to fix a certain range of year in datepicker. I only want that range of the year.
I only have the DatePickerDialog object and a OnDateSetListener object, how do I incorporate a datepicker into this arrangement?
Try getting the DatePicker from the dialog using DatePickerDialog.getDatePicker() and then using DatePicker.setMaxDate() and DatePicker.setMinDate()

Categories

Resources