JMR*_*ies 2 android togglebutton
我有一个togglebutton,它没有响应我的setChecked(...)方法.这是代码:
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);
Run Code Online (Sandbox Code Playgroud)
日志报告mBool为true,当我mToggle.setChecked(mBool)按下时按钮保持在关闭位置.
这是按钮的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"/>
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
请使用原始布尔值设置状态
//set true or false based on your prefs
boolean mBool = true;
mToggle.setChecked(mBool);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
23147 次 |
| 最近记录: |