Reputation: 33509
I am trying to use getDisplayNames()
on a Calendar object in my Android code. I have java.util.Calendar
included and haven't had any troubles using any other public members of the Calendar class (i.e. Calendar.MONTH). Now I am attempting the following line...
mReminderCal.getDisplayName(Calendar.DAY_OF_MONTH, Calendar.LONG, Locale.US)
And Eclipse is telling me Calendar.LONG
or Calendar.SHORT
don't exist.
According to the documentation here they should exist: http://developer.android.com/reference/java/util/Calendar.html#LONG
Any insight?
Upvotes: 6
Views: 3650
Reputation: 33509
I found the issue.
The getDisplayName()
and associated Calendar.LONG
and Calendar.SHORT
are API level 9 only. I'm on API level 4 for backwards compatibility. I suppose, I will have to create my own function to translate the month enums into strings.
Upvotes: 4
Reputation: 3606
Try This (same for Gregorian or regular calendar). DateFormatSymbols is API level 1.
int month = date.get(GregorianCalendar.MONTH);
String monthName = new DateFormatSymbols().getMonths()[month];
Upvotes: 6
Reputation: 43098
you can use
mReminderCal.getDisplayName(java.util.Calendar.DAY_OF_MONTH, java.util.Calendar.LONG, Locale.US);
or static imports:
import static java.util.Calendar.DAY_OF_MONTH;
It seems that you have already imported android's Calendar
class, and in your line you try to get the fields from that class. So, you need to tell compiler explicitly what exact Calendar
you use.
Upvotes: 2