How to save the state of the checkbox when it is checked and a button pressed
<p>Aim is to save the background color of a textview whenever a checkbox is checked and a button is pressed while it will revert back to its normal state when redoing it.</p>

<p>I know that to do that i can use shared preferences but somehow it doesn't work (NOT SAVED). Here is the codes that i have used (checkbox is created programtically not though xml)</p>

<pre><code>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();
                }
            });
        }
    }

}
</code></pre>
