I am setting an alarm for which I take the Hour and Minutes from a TextView
and the AM/PM through a Spinner
. Here is how I initialize the Calendar
object:
Calendar calen = Calendar.getInstance();
calen.set(Calendar.HOUR_OF_DAY, alarmHour); //alarmHour from TextView
calen.set(Calendar.MINUTE, alarmMinute); //alarmMinute from TextView
calen.set(Calendar.SECOND, 0);
calen.set(Calendar.MILLISECOND, 0);
if(amorpm.equals("PM") //amorpm from Spinner
{
calen.set(Calendar.AM_PM, Calendar.PM);
}
else
{
calen.set(Calendar.AM_PM, Calendar.AM);
}
The problem is the Hour value of this Calendar
object is sometimes correct i.e. the value which the user enters in the TextView
(and it is always 1 to 12). But sometimes, the value is equal to the current Hour. For example, if the current time is 11:30 pm, and I set the alarm for 9:30 am, then the Hour field has the value 11. One strange thing is that when I change the name of the Calendar
object to something else, say cal, it works. But wont work later. What could be wrong ?
Thanks for your help!