title: How to edit a ListPreference value from java code in Android
body: <p>I know how to change the value of a <code>CheckBoxPreference</code>, but I can't get it to work for a <code>ListPreference</code>.</p>
  
  <p>Here is how my preference screen is built:</p>
  
  <ul>
  <li>one <code>CheckBox</code> for the default</li>
  <li>A <code>ListPreference</code> to select a color other than the default.</li>
  </ul>
  
  <p>The <code>ListPreference</code> is defined with the key "titleColor", as follows :  </p>
  
  <pre><code>CharSequence[] entries = { "Dark grey", "Light grey", "Light red", "Red" };
  CharSequence[] entryValues = { "#4c4c4c", "#b5b5b5", "#ab6a68", "#962622" };
  final ListPreference color = (ListPreference) findPreference("titleColor");
  color.setEntries(entries);
  color.setEntryValues(entryValues);
  </code></pre>
  
  <p>Now, when I select a color I do this:  </p>
  
  <pre><code>color.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
          public boolean onPreferenceChange(Preference preference, Object newValue) {
              System.out.println("In the onClick method");
              System.out.println("change title color");
              Editor editor2 = defaultColor.getEditor();
              editor2.putBoolean("defaultColor", false);
              editor2.commit();
              return true;
          }
  
      });
  </code></pre>
  
  <p>And this seems to work, though I'm not sure to do this properly.</p>
  
  <p>Now I have been trying to do something similar when I select the default color, but I can't get the list to either uncheck everything OR check a color that would be the default.</p>
  
  <p>Any idea?</p>