title: Saving checkbox status as SharedPreference unsuccessful
body: <p>I am trying to set up a profile where a user selects male or female via a checkbox representing each. I then try to save this data using SharedPreference object. Have added a onClickListener to both checkboxes and if checked a boolean value is set to true.</p>
  
  <p>But no matter what i have tried  (and i have tried this for 4 hours!!!!!) when i refresh the activity both boxes are checked and both boolean values are true! Any ideas would be great.</p>
  
  <pre><code>// check box initialisation male and female
          male = (CheckBox) this.findViewById(R.id.cb_MalePrfofile);
          male.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // when male is checked
                  if (((CheckBox) v).isChecked()) {
                      sex = "Male";
                      //malePref=true;
                      //femalePref=false;
                      female.setChecked(false);
                      Toast.makeText(getBaseContext(), "malePref=true", Toast.LENGTH_SHORT).show();
                  }
              }
          });// end on click for male
  
          // if female check box is checked
          female = (CheckBox) this.findViewById(R.id.cb_FemalePrfofile);
          female.setOnClickListener(new View.OnClickListener() {
  
              @Override
              public void onClick(View v) {
                  // when male is checked
                  if (((CheckBox) v).isChecked()) {
                      sex = "Female";
                      //femalePref=true;
                      //malePref=false;
                      male.setChecked(false);
                      Toast.makeText(getBaseContext(), "feamlePref=true", Toast.LENGTH_SHORT).show();
                  }
              }// end onClick/if
          });// end on click call for male
      }// end intilize widgets
  </code></pre>
  
  <p>Setting the SharedPref editor:</p>
  
  <pre><code>//Checkboxes
          if(male.isChecked()){
              //boolean maleValue=true;
          editor.putBoolean("maleValue", true);
          }else if(female.isChecked()){
              //boolean femaleValue=true;
              editor.putBoolean("femaleValue", true);
          }//end else
  </code></pre>
  
  <p>the onCreate method to set data according to saved preferences:</p>
  
  <pre><code>male.setChecked(prefs.getBoolean("maleValue", false));
  female.setChecked(prefs.getBoolean("femaleValue", false));
  </code></pre>
  
  <p>The XML:</p>
  
  <pre><code>&lt;CheckBox
                  android:id="@+id/cb_MalePrfofile"
                  android:text="Male"
                  android:typeface="serif"
                  android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          &gt;&lt;/CheckBox&gt;
                 &lt;CheckBox
                  android:id="@+id/cb_FemalePrfofile"
                  android:layout_width="wrap_content"
                  android:text="Female"
                  android:typeface="serif"
  
          android:layout_height="wrap_content"&gt;&lt;/CheckBox&gt; 
  </code></pre>
  
  <p>Answering comments:
  I have the editor.commit() in place already and all other data from spinners, edit texts etc saved fine.</p>
  
  <p>Also have tried adding a Radiogoup but no matter which i select the Male is selected by default overtime activity reloads. Sorry about the long code here but am posting the onCreate method as maybe missing something here:</p>
  
  <pre><code>// TODO Auto-generated method stub
          super.onCreate(savedInstanceState);
          this.setContentView(R.layout.profile);
          intilizeWidgets();
  
          //load teh sahred prefs object
          prefs = this.getSharedPreferences(prefFilename, MODE_PRIVATE);
          //SharedPreferences.Editor editor = prefs.edit();
  
          //save teh sored values in the Edittexts
          firstName.setText(prefs.getString("firstName", null));
          lastName.setText(prefs.getString("lastName", null));
          insuranceNo.setText(prefs.getString("insuranceNumber", null));
          padiNumber.setText(prefs.getString("padiNum", null));
          aboutMe.setText(prefs.getString("aboutMe", null));
  
          boolean maleBoo = prefs.getBoolean("maleValue", false);
          Toast.makeText(getBaseContext(), "Male checked is " + maleBoo, Toast.LENGTH_SHORT).show();
  
          male.setChecked(prefs.getBoolean("maleValue", false));
  
          female.setChecked(prefs.getBoolean("femaleValue", false));
          boolean femaleBoo = prefs.getBoolean("femaleValue", false);
          Toast.makeText(getBaseContext(), "FeMale checked is " + femaleBoo, Toast.LENGTH_SHORT).show();
  
          certLevel.setSelection(prefs.getInt("certLevel", 0));
          yearsExperince.setSelection(prefs.getInt("yearsExp", 0));
  
          //radiobuttons
          isMaleButton.setChecked(prefs.getBoolean("maleButton", false));
          isFemaleButton.setChecked(prefs.getBoolean("femaleButton", false));
  
  
      }// end onctreate
  </code></pre>
  
  <p>When the Save button is clicked I get the Shared pref object and Editor</p>
  
  <pre><code> public void onClick(View arg0) {
              //get the sahred pref object and its editor to accept values
              this.prefs = this.getSharedPreferences(prefFilename, MODE_PRIVATE);
              SharedPreferences.Editor editor = prefs.edit();
      if(isMaleButton.isChecked()){
              editor.putBoolean("maleButton", true);
              }else if(isFemaleButton.isChecked()){
              editor.putBoolean("femaleButton", true);
  
  
              }
  </code></pre>