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

前端 未结 4 388
囚心锁ツ
囚心锁ツ 2021-01-07 02:09

I have a togglebutton which is not responding to my setChecked(...) method. Here is the code:

mBool = mPrefs.getBoolean(\"buttondefault\", true);
Boolean b =         


        
相关标签:
4条回答
  • 2021-01-07 02:52

    Please use primitive boolean to set the state

    //set true or false based on your prefs
    boolean mBool = true;
    mToggle.setChecked(mBool);
    
    0 讨论(0)
  • 2021-01-07 02:57

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

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-01-07 03:07

    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.

    0 讨论(0)
提交回复
热议问题