Date is shown twice if setMaxDate is used on DatePickerDialog - android

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

Related

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.

DatePickerDialog display year picker first

I want my DatePickerDialog as soon as it opens to display the list of years.
For example, when I show the dialog I see the calendar view:
:
If I tap on the text "1900" the year view is shown:
I tried this code but it had no effect and I'm clueless for what I could do:
DatePickerDialog birthDatePicker = new DatePickerDialog(getActivity(), this, 0, 0, 0);
birthDatePicker.getDatePicker().setSpinnersShown(true);
birthDatePicker.show();
Same as Show year selection first in Android Calendar View
I will copy here my answer:
You can get a reference to year view and then just simulate user click to open it.
dataPicker.getTouchables().get( 0 ).performClick();
Using the Datepicker XML modifications you can elect to show spinners instead of the Calendar, which might be beneficial for you as you want to directly edit the years.
android:datePickerMode="spinner"

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

Android DatePickerDialog to a year of history

I'm coding an android app about the egyptian history, and I want to add a DatePicker in a dialog, where I will show years, and whenever the user sets a year, it shows in the layout the events in that year . If he changes the year, the event changes ...etc
It is a historical app, and I don't know how to do it!
I need help.
According to the doc (http://developer.android.com/reference/android/widget/DatePicker.html)
You can set min and max date according to the era you want to cover:
android:maxDate The minimal date shown by this calendar view in mm/dd/yyyy format.
android:minDate The minimal date shown by this calendar view in mm/dd/yyyy format.
And then use the onDateChangedListener to display the correct Layout.
http://developer.android.com/reference/android/widget/DatePicker.OnDateChangedListener.html
As you want to use only a year, I would advise to use a NumberPickerDialog instead.
DatePicker is maybe "too much" for your use case.

Android date popup, range

I have a date picker that allows a user to select a date, by default this lets you change the year higher and higher to infinite or something, but I want to confine the user to a maximum year. Such as only 2 years from now.
new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay)
How do I set the max date within that function? I'm sure I can do a "if date > 2014 , then show a toast message and show the datepicker again until they select a proper date" but I would prefer to just not let the date picker function go above a certain year.
Insight appreciated!
Add a OnDateChangedListener to DatePicker Object and then override the
#Override
public void onDateChanged(DatePicker view, int year, int monthOfYear,
int dayOfMonth) {
//Do the check here for the year
}
Hope this helps
Create a datepicker and add that view to your dialog layout, If you want any custom behaviour then you need a custom date picker, override the onDateChanged() to behave as per your need.
If just you need is to restrict the maximum date of the date picker, use setMaxDate(long maxDate) for the datepicker.
you can use getDatePicker() on the dialog to get the instance of the it inside the dialog.
refer http://developer.android.com/reference/android/app/DatePickerDialog.html
and http://developer.android.com/reference/android/widget/DatePicker.html
for more info.

Categories

Resources