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/
Related
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.
In some old APIs numberPickerView not Working.So if i use this view in a project manifest have to be set to higher.That means program not working in old APIs.So my questions are
Is there any View give same functionality in all APIs in Android?
Or is any way to show NumberPickerView in layout when run in latest APIs and show another view to enter numbers(Like EditText) in the place of NumberPickerView when running on older version?
It was added in api 11. If you want pre-11, check this code:
https://github.com/michaelrnovak/numberpicker
You're welcome.
I would like to use the brand new Date Picker and Time Picker that is now part of the new official Google Calendar App.
http://googlesystem.blogspot.de/2013/05/new-google-calendar-controls-for-android.html
All I found so far is this source code on grepcode but I can't find the widgets or fragments or activities there.
http://grepcode.com/snapshot/repository.grepcode.com/java/ext/com.google.android/android-apps/4.2.2_r1/
Is that already public or is there something similar out there?
I think the code you are looking for can be found here:
https://android.googlesource.com/platform/frameworks/opt/datetimepicker/+/master/src/com/android/datetimepicker
There is some pretty directly usable source code snippets in this Android Developer Pages:
http://developer.android.com/guide/topics/ui/controls/pickers.html
I used it as-is and all works just fine.
Also, reference these:
DatePickerDialog
http://developer.android.com/reference/android/app/DatePickerDialog.html
TimePickerDialog
http://developer.android.com/reference/android/app/TimePickerDialog.html
DialogFragment
http://developer.android.com/reference/android/support/v4/app/DialogFragment.html
I started working with CalendarView today, and to my surprise, class is very inflexible.
Only methods that CalendarView allos me to override are:
getDate()
getFirstDayOfWeek()
getMaxDate()
getMinDate()
getShowWeekNumber()
isEnabled()
setDate(long, boolean, boolean)
setDate(long)
setEnabled(boolean)
setFirstDayOfWeek(int)
setMaxDate(long)
setMinDate(long)
setOnDateChangeListener(OnDateChangeListener)
setShowWeekNumber(boolean)
However, i need to customize how certain days are displayed. For example, in my database i have events for dates 2013-10-02 and 2013-12-02 and i want to highlight these days in my calendar. How would i go about that.
You need to build your own CustomCalenderView.
Extends the Native CalendarView and build the behaviour that you want to color the background.
Or you can use this library : TimesSquare for Android.
And think it provide what you are looking for .
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.