Android: I can't find getFullYear() - android

I'm using the java Date Class in eclipse for Android as getYear is soon to be deprecated and replaced with getFullYear but the Class doesn't have the getFullYear function... What do I need to do to get it??

Use
Calender statcal = Calender.getInstance(Locale locale)
and then access the field statcal.get(Calendar.YEAR). That should do it.

If you are just looking to use the result for display purposes, I would recommend using the android.text.format.DateFormat class in android.
http://developer.android.com/reference/android/text/format/DateFormat.html
You can simply do
DateFormat.format("yyyy", dateObject);
The dateObject can be a Calendar, Date or timeInMillis

Related

How to disable all days till today in Caldroid calendar?

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

how to set date in android WeekView library?

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

Looking for the source code of the new Google Calendar Time and Date Picker Widgets

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

How to localize Android DatePicker?

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

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.

Categories

Resources