> Neither of my ListPreference values persist from one run to the next.
> Sometimes even in the same run, if I bring up preferences the
> ListPreference values will be back to the default values.
>
> Here is the Settings xml
>
> <?xml version="1.0" encoding="utf-8"?>
> <PreferenceScreen
>       xmlns:android="http://schemas.android.com/apk/res/android";>
>       <EditTextPreference
>               android:key="weight"
>               android:title="@string/weightlbltxt"
>               android:defaultValue="145"
>               />
>       <ListPreference
>           android:title="@string/genderlbltxt"
>               android:entries="@array/genders"
>               android:entryValues="@array/gendervalues"
>               android:defaultValue="M"
>               />

You do not have android:key attributes for your ListPreferences. I am
surprised this does not generate a runtime exception. But, as a result, I
doubt your values are getting saved anywhere.

>       public static int GetWeight(Context context){
>               return PreferenceManager.getDefaultSharedPreferences(context)
>               .getInt("weight", 145);
>       }

It is expensive to keep reloading your SharedPreferences this way.

>       public static String GetGender(Context context){
>               return  PreferenceManager.getDefaultSharedPreferences(context)
>               .getString("gender", "Male");
>       }

Your default value should be M to line up with the contents of your string
arrays. "Male" is a display value.

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ Version 2.0 Available!



--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to