Android: Setting preferences programmatically
<p>I have a small ap with preferences. In this class I've set the onPreferenceClick to get coordinates from the GPS. When the listener returns, my hope was to set the lat / long textedits automatically. I've tried every source sample out there, no luck:</p>

<pre><code>public void onLocationChanged(Location l) {
  Log.d("H","Location Received: "+l.toString());
  prefLocation.setSummary(l.toString());
  SharedPreferences settings = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
  SharedPreferences.Editor editor1 = settings.edit();
  editor1.putString("posLat","xxx");
  editor1.commit();
}
</code></pre>

<p>When this code executes when I click on my PreferenceScreen and the location listener returns, the EditTextPreference with the key "posLat" still shows the old value.</p>

<p>I'm going crazy trying to figure out what's wrong!</p>

<p>My prefs.xml:</p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;PreferenceScreen
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:key="My_Shared_Preferences"&gt;
    &lt;PreferenceCategory
        android:title="Your Location"&gt;
        &lt;PreferenceScreen
            android:title="Find Location..."
            android:key="location"
            android:summary="Click here to read your location automatically"/&gt;
        &lt;EditTextPreference
            android:title="Latitude" 
            android:key="posLat" /&gt;
        &lt;EditTextPreference
            android:title="Longtitude" 
            android:key="posLong" /&gt;
        &lt;EditTextPreference
            android:title="Altitude" 
            android:key="posAlt" /&gt;
    &lt;/PreferenceCategory&gt;
&lt;/PreferenceScreen&gt;
</code></pre>

<p>Alternatively, maybe there is a better way to store the location value for an application? I don't really want the user to manually enter the coordinates, but I dont want to resort to saving and loading a text file with the settings, it seems so crude.</p>
