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 .
Related
I'm using Caldroid library https://github.com/roomorama/Caldroid. I want to disable all dates earlier than today. How can I do that? There is method setDisableDates, but it requires passing as argument list of dates to disable.
I found solution - use method setMinDate.
This will work for you:
setMinDateTime(getToday());
use in customizeTextView() in CaldroidGridAdapter class
I want to implement android WeekView in my calendar application.For that i used this https://github.com/alamkanak/Android-Week-View library. Now the problem is i cant set date in that WeekView .
Never tried it because I never used this lib, but looking at the code, it seems this does what you want :
public void goToDate(Calendar date)
There is also a convenience method to go straight to today :
public void goToToday()
goToDate is deprecated use scrollToDate
I put the DatePicker on my Activity. Everytime I launch my app I see english version of date in the DatePicker widget: Oct 15 2012. But I want to have a local version of date (russian) when I start my Activity. I've tried to define the locale before UI initialization. But it doesn't help. Is there any possibility to make it without extending DatePicker class?
In fact there is no need to override this class. But when I started to do it, I found info about special method "reorderpickers" which is specially designed to localize datepicker (automatically). My mistake was in setting Locale to English in the previous activity (to define English locale for password). That's why the standard method didn't work. So anybody who has the same problem check your code whether you have changed Locale.
You should create your custom datepickerdialog. For make this, that link help you;
http://coffeebreak.hiq.se/2011/09/09/fixing-androids-datepickerdialog/
Additional information for DataPicker and application locale you can find here
I am implementing a DateTimePicker. I have reuse this repository.
The problem appears when I am trying to catch the events for the onTimeChanged() method when I change the minutes. If I use the buttons of + and – it's fine, the event is fired and I can handle it here:
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// Update the internal Calendar instance
mCalendar.set(mCalendar.get(Calendar.YEAR),
mCalendar.get(Calendar.MONTH),
mCalendar.get(Calendar.DAY_OF_MONTH),
hourOfDay, minute);
}
Whereas when I click on the minutes and I change it using the keyboard the event doesn't arise, as in the case of the hours, days, etc…
A more detail description of the problem is:
What steps will reproduce the problem?
Select the time picker
Touch on the numbers, so the keyboard appears
when I write an amout of minutes, the event doesn't fire
What is the expected output? What do you see instead?
I would expect to catch this event inside onTimeChanged(), but I cant.
What version of the product are you using? On what operating system?
Version 2. On Android Froyo.
The author of this code has told me there is a bug on Android. I think should be a work around to this problem, for example creating my own class extending from TimePicker and reimplementing the interface OnTimeChangedListener.
What is the best option to listen the timerPicker events?
DatePicker control must call clearFocus() in order to trigger
onFocusChanged() and that will fix the issue.
PFB the link that might help you :
http://code.google.com/p/android/issues/detail?id=2745
Thanks!
The event is fired in the same way as the onchange Event in HTML:
It only fires after leaving the text boxes, and going to the next one.
I can't tell if it's really a bug or some kind of feature.
You could just catch the KeyEvent.Callback when extending the TimePicker class. Then you should get informed about every single key press inside the EditText controls internally used by the TimePicker.
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/