android - Set CheckBox enabled if togglebutton is checked -


i created togglebutton push notification service (if button checked, notifications reveived). want, when check button, checkbox checkbox. if button isn't check, checkbox should disabled.

i used code, not work. when togglebutton off, checkbox disabled. not work otherwise.

        togglebutton toggle = (togglebutton) findviewbyid(r.id.tooglenotifications);      toggle.setchecked(pushbots.sharedinstance().isnotificationenabled());     toggle.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {             pushbots.sharedinstance().togglenotifications(ischecked);             chicken.setenabled(false);         }     });      if (toggle.ischecked()) {         chicken.setenabled(true);     } 

i not sure trying implement enable/disable checkbox on toggle change, should that:

 toggle.setoncheckedchangelistener(new compoundbutton.oncheckedchangelistener() {         public void oncheckedchanged(compoundbutton buttonview, boolean ischecked) {             pushbots.sharedinstance().togglenotifications(ischecked);             chicken.setenabled(ischecked);         }     }); 

and don't need part:

    if (toggle.ischecked()) {         chicken.setenabled(true);     } 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -