Open zyxq opened 9 years ago
Yes how can we set initial state?
In the onCreate(), Calling post before toggle is required, otherwise you will run into NULL error. I believe it may not be initialized.
togglebtn.post(new Runnable() { @Override public void run() { if (sharedPref.getBoolean(preference, false)) { if (!togglebtn.isChecked()) { togglebtn.toggle(); } } } });
@hongzhou85 is right. If you call the toggle method in your Activity's onCreate() callback you get a NullPointerException. Currently the runnable seems to be the only working solution (calling the toggle method in the onResume() callback isn't appropriate, imho).
I did my own custom class which extends MaterialAnimatedSwitch and sets the initial state.. but the developer of this pretty library should take care of it.
I'm getting stuck with this as well, I hope the developer will manage to fix this as soon as possible. @andrearinaldispotsoftware, you said you managed to extend MaterialAnimatedSwitch and set the initial state. I tried to do that as well but... how did you set the initial state in the extended class?
I'm Having the same problem. It's too bad we have to call to the runnable each time we want to init the switch... hope it will be fixed soon :\
I also hope it will be fixed ASAP
I also hope it will be fixed ASAP
is the any method to set init state?