Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

mBool = mPrefs.getBoolean("buttondefault", true);
Boolean b = mBool; //Only creating this for Logging, mBool IS PRIMITIVE
Log.e("Update pref", b.toString());
mToggle = (ToggleButton)findViewById(R.id.ac_toggle);
mToggle.setOnClickListener(this);
mToggle.setChecked(mBool);

The log reports mBool to be true, let when I do mToggle.setChecked(mBool) the button remains in the off position.

Here is the xml for the button:

<ToggleButton android:id="@+id/ac_toggle"
android:textOn="Yes"
android:textOff="No"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="3sp"
android:layout_weight="5"/>

Any ideas?

like image 592
JMRboosties Avatar asked Mar 07 '26 12:03

JMRboosties


1 Answers

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.

like image 125
JMRboosties Avatar answered Mar 10 '26 01:03

JMRboosties