Android API 21 22 datepicker year selection bug? - android

I've implemented the "calendar view", i.e., lollipop version of Android's Datepicker.
There's a difference between Android API 21 & 22 in the year selection of said datepicker when I click on "2015" to change the year:
using API21
using API22
I'm using a Nexus 5 simulator. I'm only seeing the current (2015) year entry in API22, whereas in API21, I can scroll through from ~1950 to ~2100. Same code and, as far as I can tell, same simulation settings.
I'm wondering if this is just a bug, if anyone else has encountered it, or has any tips for a workaround? I really like the calendar view that Lollipop offers so preferable if I can get this working right. Will update with any new information I find.

Found a quick fix. Programmatically set the min and max dates of the DatePickerDialog object. I did so in the DatePickerFragment static class definition, so every instance of DatePickerDialog gets set:
DatePickerDialog datePickerDialog = new DatePickerDialog(getActivity(), YourActivityHere, year, month, day);
datePickerDialog.getDatePicker().setMinDate(datePickerDialog.getDatePicker().getMinDate());
datePickerDialog.getDatePicker().setMaxDate(datePickerDialog.getDatePicker().getMaxDate());
You can also set this if you defined DatePickerDialog in an XML activity, but I'm not sure if the bug exists there.

Related

calendar View in android 3.0

I am trying to bring in the default Calendar's view into my app and i found its possible using this
CalendarView calander = new CalendarView(this);
setContentView(calander);
This shows the calendar in month mode. Is it possible to make the CalendarView show the calendar in hourly mode?
I think you will need to write a custom implementation for that?

How do you get a DatePicker from a DatePickerDialog?

I have a activity that is popping up a android.app.DatePickerDialog.
DatePickerDialog dialog = new DatePickerDialog(this, startDateSetListener, start_cal.get(Calendar.YEAR), start_cal.get(Calendar.MONTH), start_cal.get(Calendar.DATE));
I want to get at the DatePicker View from the DatePickerDialog so that I can set the min and max dates. The API reference says that there is a method getDatePicker and that has been there since API 1 but it is invalid, my ide doesn't like it.
DatePicker picker = dialog.getDatePicker();
"The method getDatePicker() is undefined for the type DatePickerDialog"
Any one know what API was the method created in or how I can get to the DatePicker to edit min/max dates?
I am using API 7, Platform 2.1.
Despite that getter method only being available in Honeycomb and above (as dmon correctly pointed out), you can still fairly easily get access to the DatePicker object encapsulated by the DatePickerDialog using reflection. It'll look something like this:
DatePickerDialog dialog = ... // create dialog
Field mDatePickerField = dialog.getClass().getDeclaredField("mDatePicker");
mDatePickerField.setAccessible(true);
DatePicker mDatePickerInstance = (DatePicker) mDatePickerField.get(dialog);
From this point on, you have a reference to the internal DatePicker object and you should be able to change it to your own liking. Please do beware of any obvious typos, as I entered this directly into the browser.
You misread, it's only available since API 11:
"public DatePicker getDatePicker () Since: API Level 11". Look closely.

DatePicker look and feel

Hi i've a HTC Desire and want a date pciker to look like the spinning wheels in the datepicker i see in the agenda etc. If i use this code
return new DatePickerDialog(this,
mDateSetListener,
mYear, mMonth, mDay);
I always see the default datepicker with up and down buttons without the swipe to spin the wheels. Is there a sample of how to use these
Greetings Andre Mens
Without actually modifying the built in DatePicker and compiling your own build of Android, you're going to need to use a third party solution. This may (or may not) work for you -
http://code.google.com/p/android-wheel/

How to customize a TimePickerDialog?

I'm looking to create something EXACTLY like TimePickerDialog (look and feel) in Android, but it would be for MINUTES/SECONDS, not HOURS/MINUTES. Therefore AM/PM would not be relevant and would therefore allow MINUTE to be greater than 24 (making the max 59).
Is it possible to change the TimePickerDialog instance in any way to reflect this?
Any and all suggestions would be greatly appreciated. :-)
Is it possible to change the TimePickerDialog instance in any way to reflect this?
No, but the layout and source code to TimePickerDialog are both available as a starting point for implementing your own dialog.
This might help:
TimePicker with seconds:
https://github.com/IvanKovac/TimePickerWithSeconds
Have a look.
As the links in CommonsWare's answer are now dead, you might want to know that the source for TimePickerDialog is probably already on your local machine - it is included in the SDK. Try looking in the following locations:
[SDK_HOME]/sources/android-23/android/app/TimePickerDialog.java
or
[SDK_HOME]/sources/android-23/com/android/datetimepicker/time/TimePickerDialog.java
[SDK_HOME]/platforms/android-23/data/res/layout/time_picker_dialog.xml
Of course, choose the Android version that you want to borrow from. References to R. should be to android.R. Unfortunately, there seem to be some visibility issues with ValidationCallback - even on recent SDK levels.

Android Calendar View for Date Picker

I'm writing my first app, and I have a question about DatePicker.
My app requires the user to input a date. The most user-friendly way would be to popup a calendar-like widget that displays the current month like a calendar grid - something like this:
I want to use that in place of the DatePicker interface - which has Month, Day, and Year fields, each with an up and down button to increment/decrement.
Is this type of functionality built into any Android widget or view, or would I have to design my own custom component to do this? I figured this would already exist, seeing how much this type of UI is used so frequently in non-mobile apps and web pages.
Thanks!
Now, in 2014, even the native DatePicker (link) contains small Holo looking CalendarView (link) to pick a day in month.
You can choose, if both spinners and CalendarView or just one of them is displayed by setting:
android:calendarViewShown
android:spinnersShown
I'm not sure if it's just API level 16+ or if it was even in Ice Cream Sandwich, but it's there. This is how it looks by default:
Moreover, on API level 21 and higher there is a new Material themed DatePicker that looks like following:
This is default on API 21+ and there are no spinners anymore, but you can switch back to the Holo one by setting
android:datePickerMode="spinner"
in your XML.
Since the API 11 there natively: CalendarView
This View is in HoloEverywhere since API 7.
Is this type of functionality built into any android widget or view, or would I have to design my own custom > component to do this?
There is no component for that in the Android SDK, sorry. The widget you illustrate is too small for a touchscreen. You can implement something larger (see the Calendar app), but you are largely on your own for that.
what i found so far:
http://code.google.com/p/android-calendar-view
http://code.google.com/p/openintents/wiki/CalendarPickerAPI
I have recently written exactly this as a modular app. Here is some sample code, documentation with screenshots, and .apk download.
Found a good implemetation in http://caughtinthemobileweb.wordpress.com/2011/06/20/how-to-implement-calendarview-in-android/
Also Since API level 11 (Android 3.0) there has been the native implementation of the CalendarView http://developer.android.com/reference/android/widget/CalendarView.html
Try to use this component:
https://github.com/truefedex/android-date-picker
If you want to use it like popup write on your onclick:
if (calendarPopup == null) {
calendarPopup = new PopupWindow(getContext());
CalendarPickerView calendarView = new CalendarPickerView(getContext());
CalendarNumbersView calendar = (CalendarNumbersView) calendarView.findViewById(com.phlox.datepick.R.id.calendar);
calendar.setShowDayNames(false);
calendarView.setListener(onDateSelectionListener);
calendarPopup.setContentView(calendarView);
calendarPopup.setWindowLayoutMode(
MeasureSpec.makeMeasureSpec(llCalendar.getWidth(), MeasureSpec.EXACTLY),
ViewGroup.LayoutParams.WRAP_CONTENT);
calendarPopup.setHeight(1);
calendarPopup.setWidth(llCalendar.getWidth());
calendarPopup.setOutsideTouchable(true);
}
calendarPopup.showAsDropDown(llCalendar);
you can use this lib for date selection
https://github.com/square/android-times-square/

Categories

Resources