Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to set the init state #11

Open
zyxq opened this issue Aug 3, 2015 · 7 comments
Open

How to set the init state #11

zyxq opened this issue Aug 3, 2015 · 7 comments

Comments

@zyxq
Copy link

zyxq commented Aug 3, 2015

is the any method to set init state?

@hongzhou85
Copy link

Yes how can we set initial state?

@hongzhou85
Copy link

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();
}
}
}
});

@andrerinaldi
Copy link

@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.

@MarKco
Copy link

MarKco commented Oct 20, 2015

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?

@moheny
Copy link

moheny commented Nov 24, 2015

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 :\

@Andecy
Copy link

Andecy commented Mar 3, 2016

I also hope it will be fixed ASAP

1 similar comment
@Yanruplus
Copy link

I also hope it will be fixed ASAP

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants