I need to be able to choose date and time in my application It should either be done by using a dialog, or starting a new intent.
The way I have done it now, is that I have started a new intent, since I need to set both date and time.
My problem is that I need to set the current date on the Datepicker
(This is possible with the Timepicker
using setCurrentHour
and setCurrentMinute
) onCreate, and set that as a lower boundary.
I can't find any functions in the Android API for doing this with the DatePicker
.
Anyone have a suggestion to solve this problem?
Thanks in advance!
Edit:
Important: The DatePicker
and TimePicker
must be in the same dialog/intent
For OnDateSetListener typecast the getActivity method to OnDateSetListener. For the year, month, and dayOfMonth create an instance of calendar class and assign the year, month, and dayOfMonth to variables of type int. Pass year and month and dayOfMonth so that when the DatePickerDialog opens it has the current date.
$(". selector"). datepicker( {defaultDate:"+6"} );
The datepicker is tied to a standard form input field. Focus on the input (click, or use the tab key) to open an interactive calendar in a small overlay. Choose a date, click elsewhere on the page (blur the input), or hit the Esc key to close. If a date is chosen, feedback is shown as the input's value.
Straight to code
Calendar c = Calendar.getInstance();
int mYear = c.get(Calendar.YEAR);
int mMonth = c.get(Calendar.MONTH);
int mDay = c.get(Calendar.DAY_OF_MONTH);
DatePickerDialog dialog =
new DatePickerDialog(this, mDateSetListener, mYear, mMonth, mDay);
dialog.show();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With