On Wed, Jul 7, 2010 at 5:33 PM, Bret Foreman <bret.fore...@gmail.com> wrote:

> I can't understand from the Preferences and ListPreference documents
> whether the defaultValue attribute in preferences.xml should be the
> text choice displayed in the list, the Integer corresponding to that
> choice, or the index of the choice.
>

It's what the name implies - the VALUE you would expect to get from
getWhatever() methods of SharedPreferences. So if you have a boolean, the
default should be "true" or "false", not "Enabled" or "Disabled" (your
possible text displays) nor 0 or 1 (index values).

Similarly for int value, it's 0, 1, or 3453463, or whatever. Etc, etc.


> It also seems like best practice to pick up the default value from the
> keys in arrays.xml rather than put in a literal string. Can someone spell
> out how it should work?
>

You'd probably have to have values in your res/ folder which you then
reference with the '@' notation. I find this more cumbersome than it's worth
so I don't bother, though it may be a good idea if your project is large and
/ or the preferences change a lot. Mine don't.

Suppose I want the default choice to be Fahrenheit. What should be the
> value of defaultValue?
>

Again, the VALUE you expect to get in code if nothing exists - in this case,
1.

-------------------------------------------------------------------------------------------------
TreKing - Chicago transit tracking app for Android-powered devices
http://sites.google.com/site/rezmobileapps/treking

-- 
You received this message because you are subscribed to the Google
Groups "Android Beginners" group.

NEW! Try asking and tagging your question on Stack Overflow at
http://stackoverflow.com/questions/tagged/android

To unsubscribe from this group, send email to
android-beginners+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-beginners?hl=en

Reply via email to