目的是保存textview的背景颜色,只要复选框被选中并且按下按钮时它将在重做时恢复到正常状态它。如何保存复选框的状态,当它被选中并且按下一个按钮时
我知道这样做我可以使用共享首选项,但不知何故它不起作用(不保存)。这里是代码,我已经使用(复选框创建程式设计虽然不是XML)
status=(Button)findViewById(R.id.status);
CheckBox checkbox = new CheckBox(myContext);
tr.addView(checkbox);
checkbox.setOnCheckedChangeListener(new OnCheckedChangeListener(){
public void onCheckedChanged(CompoundButton arg0, boolean isChecked) {
// TODO Auto-generated method stub
if (isChecked){
status.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
// TODO Auto-generated method stub
//myEditor.putInt("backColor", Color.LTGRAY);
//tr.setBackgroundColor(Color.LTGRAY);
mySharedPreferences=getSharedPreferences(MYPREFS,0);
SharedPreferences.Editor myEditor;
myEditor=mySharedPreferences.edit();
final int backColor=mySharedPreferences.getInt("color", Color.LTGRAY);
tr.setBackgroundColor(backColor);
myEditor.putInt("color", backColor);
myEditor.commit();
}
});
}
}
}
http://stackoverflow.com/questions/6800244/android-how-to-save-the-state-of-a-checkbox –
嗨,我也发现了这一点,但我希望textview的颜色改变颜色当一个复选框被选中并且一个按钮被点击时......不改变复选框的颜色......我希望任何人都可以提供一些帮助代码,这是为了我的学校项目......谢谢 – user996824
我看不到任何东西显然这里错了,你的代码重新加载颜色怎么样? – dten