uiswitch - Switch miss first call. Android -
i want rebuild app https://github.com/sheldonneilson/android-alarm-clock , change checkbox material switch https://github.com/navasmdc/materialdesignlibrary.
set onchecklistener. problem. when start app. , checkon alarm, onchecklistener miss first call. after that, work normally.
if first action checkoff - no problem. problem in first call if want turn on alarm.
please open eyes.
@override public view getview(int position, view view, viewgroup viewgroup) { if (null == view) view = layoutinflater.from(alarmactivity).inflate( r.layout.alarm_list_element, null); final alarm alarm = (alarm) getitem(position); final switch checkbox = (switch) view.findviewbyid(r.id.switch_alarm_active); checkbox.setchecked(alarm.getalarmactive()); checkbox.settag(position); //checkbox.setonclicklistener(alarmactivity); checkbox.setonchecklistener(new switch.onchecklistener() { @override public void oncheck(switch aswitch, boolean b) { toast.maketext(alarmactivity.getapplicationcontext(), "onclick " + b, toast.length_short).show(); alarm.setalarmactive(b); database.update(alarm); alarmactivity.callmathalarmscheduleservice(); if (b) { toast.maketext(alarmactivity.getapplicationcontext(), alarm.gettimeuntilnextalarmmessage(), toast.length_short).show(); } else { toast.maketext(alarmactivity.getapplicationcontext(), "off", toast.length_short).show(); } } }); textview alarmtimeview = (textview) view .findviewbyid(r.id.textview_alarm_time); alarmtimeview.settext(alarm.getalarmtimestring()); textview alarmdaysview = (textview) view .findviewbyid(r.id.textview_alarm_days); alarmdaysview.settext(alarm.getrepeatdaysstring()); return view;
try oncheckedchangelistener()
this:
checkbox.setoncheckedchangelistener( new compoundbutton.oncheckedchangelistener() { @override public void oncheckedchanged(compoundbutton compoundbutton, boolean checked) { //do something.. } } );
Comments
Post a Comment