Android's ToggleButton setChecked(…) method not changing status of button

荒凉一梦 提交于 2019-12-01 01:03:38
JMRboosties

The code I presented was just copied from different methods. Long story short I was setting the boolean after I initialized and set the button's checked status. Apologies.

Rajdeep Dua

Please use primitive boolean to set the state

//set true or false based on your prefs
boolean mBool = true;
mToggle.setChecked(mBool);

Possibly need to call View.requestLayout() or View.forceLayout() on the buttons View to refresh the buttons state

Because the button's setChecked() method accepts a primitive boolean as parameter. you're supplying a Boolean (wrapper class) variable. Normally that should be fine, however it doesn't work on this specific method, so you might need to manually unbox the variable or change the type of mBool to boolean

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!