You never actually assign to the changedHour
or changedMinute
variables before you print them using tv1.setText
, since it's very likely that onTimeChanged
hasn't ever fired by that point. For this reason, they'll have their default values of 0, since they haven't been assigned anything else yet.
Anyway, you can't return values out of a void
function. By definition, void
is a lack of a type.
How to fix this depends on how exactly you want the code to work. The path of least resistance would be to set changedHour
and changedMinute
from within setCurrentTime
, e.g.
public void setCurrentTime() {
// TODO Auto-generated method stub
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
// NEW CODE
changedHour = hour;
changedMinute = minute;
// END NEW CODE
timePicker.setCurrentHour(hour);
timePicker.setCurrentMinute(minute);
}
You could return the hour and minute through some other mechanism (return a struct or use out parameters), but given that you update changedHour/Minute
in your onTImeChanged
callback, it probably wouldn't fit well with the existing flow.
On a re-read though, this could all just be because you're using the wrong variable in tv1.setText
. You assign to the class variables hour
and minute
in setCurrentTime
, so you could just print those rather than changedHour
and changedMinute
, e.g.
tv1.setText("Hour of Day is " + hour + " and Minute is "
+ minute);