timepicker - TimePickerFragment code always sets the same time (Android) -
i'm trying set alarm next occurrence of time (essentially, within next 24 hours). have defined timepickerfragment
used in several activities implement timepickerdialog.ontimesetlistener
.
i not need create proper alarm time (alarm
) timepicker
, want display time in textview
(timetext
). issue whenever time set user, timetext
changed 10:12 pm every time, no matter when set or set to. can imagine not being carried on properly, can't figure out what.
this entirety of timepickerfragment
:
public class timepickerfragment extends dialogfragment { int hour, minute; @override public dialog oncreatedialog(bundle savedinstancestate) { // use current time default values picker calendar c = calendar.getinstance(); hour = c.get(calendar.hour_of_day); minute = c.get(calendar.minute); // create new instance of timepickerdialog , return return new timepickerdialog(getactivity(), (timepickerdialog.ontimesetlistener)getactivity(), hour, minute, dateformat.is24hourformat(getactivity())); } }
and here relevant code 1 of implementing classes:
public void showtimepickerdialog(view v) { dialogfragment newfragment = new timepickerfragment(); newfragment.show(getfragmentmanager(), "timepicker"); } public void ontimeset(timepicker view, int hour, int minute) { alarm = new gregoriancalendar(); alarm.set(calendar.hour_of_day,hour); alarm.set(calendar.minute,minute); alarm.set(calendar.second,0); if(alarm.gettimeinmillis()<=calendar.getinstance().gettimeinmillis()) { alarm.add(calendar.date,1); } //timetext.settext(string.valueof(alarm.get(calendar.am_pm))); showalarm(); } private void showalarm() { string ampm; if(alarm.am_pm==0) {ampm="am";} else{ampm="pm";} timetext.settext(alarm.hour+":"+alarm.minute+" "+ampm); }
i'm not sure if helpful, whenever click button open timepicker , when set time it, logged: e/viewrootimpl﹕ senduseractionevent() mview == null
leads me further believe i've missed along way.
this code has undergone many changes, has never worked , @ best has produced "10:12 pm" result.
it simple , perhaps foolish mistake, figured out. android studio didn't mind me using alarm.hour
variable, wrong.
simply put, should have been using alarm.get(calendar.hour)
instead of alarm.hour
.
Comments
Post a Comment