本文介绍了Android的切换按钮setChecked(...)方法不改变按钮的状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个切换按钮没有反应到我的setChecked(...)方法。这里是code:
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);
日志报告mBool是真正,让我做 mToggle.setChecked(mBool)
按钮保持在关闭位置。
The log reports mBool to be true, let when I do mToggle.setChecked(mBool)
the button remains in the off position.
下面是XML的按钮:
<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"/>
任何想法?
推荐答案
我是白痴。在code我presented只是从不同的方法复制。长话短说,我设定布尔后,我初始化并设置按钮的检查状态。道歉。
I was an idiot. 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.
这篇关于Android的切换按钮setChecked(...)方法不改变按钮的状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!