title: How to fill ListPreference dynamically when onPreferenceClick is triggered?
body: <p>I have a preference activity that has a <code>language</code> as <code>ListPreference</code> which displays the available language list. I can fill the list when onCreate is called, but I want to fill the list when the user clicks on it. </p>
  
  <p><code>this is the java code</code> : </p>
  
  <pre><code>public class SettingsActivity extends PreferenceActivity implements OnPreferenceClickListener {
      @Override
      public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          try {
              addPreferencesFromResource(R.xml.settings);
          } catch (Exception e) {
  
          }
  
      }
  
      @Override
      public boolean onPreferenceClick(Preference preference) {
  
          if((preference instanceof ListPreference) &amp;&amp; (preference.getKey().equals("language"))){
              ListPreference lp = (ListPreference)preference;
              CharSequence[] entries = { "English", "French" };
              CharSequence[] entryValues = {"1" , "2"};
              lp.setEntries(entries);
              lp.setDefaultValue("1");
              lp.setEntryValues(entryValues);
              return true;
          }
          return false;
  
      }
  }
  </code></pre>
  
  <p>and this is the <code>settings.xml</code> (preference) :</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;PreferenceScreen
    xmlns:android="http://schemas.android.com/apk/res/android"&gt;
      &lt;PreferenceCategory android:title="General Settings"&gt;
          &lt;CheckBoxPreference android:key="enabled"  android:title="Application Status" android:summary="Enable or disable the application" /&gt;
           &lt;ListPreference 
           android:key="language" 
           android:title="Language"
           android:dialogTitle="Application language" 
           android:summary="Select the Application language"
           /&gt;
      &lt;/PreferenceCategory&gt;
  &lt;/PreferenceScreen&gt;
  </code></pre>
  
  <p>I searched but found no result! An exception occurs every time I click on that list.</p>