How to get time time picker from time picker dialog? - android

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

Related

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

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.

Android: How to get hour/min in milliseconds

I am using timepicker. I can get date(calendar) in milliseconds but cant figure out with timepicker
with date i used:
GregorianCalendar cal = new GregorianCalendar(TimeZone.getTimeZone("US/Central"));
cal.setTimeInMillis(calendarView.getDate());
Date date = new Date(calendarView.getDate() / 1000L);
long timestamp = date.getTime()
//and this works
But i dont know with timePicker becouse i get two int's: hour, min.
Im just out of plays and dont know much more to try.. Could use the help
SOLUTION:
Dummy me just need to say the problem outloud.. Hopfully it will help someone else..
long hour = timePicker.getCurrentHour();
long min = timePicker.getCurrentMinute();
hour = TimeUnit.HOURS.toMillis(hour);
min = TimeUnit.MINUTES.toMillis(min);
TimePicker is design for 24hours of day, thus you cant get date within it just hours and minutes within the day.
as the documentation is saying:
A view for selecting the time of day, in either 24 hour or AM/PM mode.
I would recommend using DatePicker to enable you to get the date.

Categories

Resources