[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread RoryD
Eck, spoke too soon - for this to work, you need to have the display values replicated somewhere in non-array form, not pretty. On Oct 2, 9:19 pm, RoryD wrote: > how about: > > SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences > (this); > String value = pref.getString("key",

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread RoryD
how about: SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences (this); String value = pref.getString("key", "default value"); Resources r = getResources(); String localizedValue = r.getString(r.getIdentifier (value,"string",null)); You may have to fiddle with the last 2 param

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread Neil
The PreferenceActivity is an almost empty class - it's the usage of the preferences in the application that I was asking about. On 2 окт, 17:21, "nEx.Software" wrote: > Hmm, I was under the impression that this was being done from a > PreferenceActivity. > > On Oct 2, 8:18 am, "Mark Murphy" wr

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread nEx.Software
Hmm, I was under the impression that this was being done from a PreferenceActivity. On Oct 2, 8:18 am, "Mark Murphy" wrote: > > Does this not work for you? > > > listPreference.getEntry()); > > That only works from a PreferenceActivity. AFAIK, it does not help if you > are looking to get the dis

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread Mark Murphy
> Does this not work for you? > > listPreference.getEntry()); That only works from a PreferenceActivity. AFAIK, it does not help if you are looking to get the display value anywhere else. -- Mark Murphy (a Commons Guy) http://commonsware.com Android App Developer Books: http://commonsware.com/b

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread nEx.Software
Without that extra closing paren of course. :) On Oct 2, 8:12 am, "nEx.Software" wrote: > Does this not work for you? > > listPreference.getEntry()); > > On Oct 2, 7:40 am, Neil wrote: > > > That's an idea, but it's messy.  I can't believe that the best way to > > solve this is to repeat that c

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread nEx.Software
Does this not work for you? listPreference.getEntry()); On Oct 2, 7:40 am, Neil wrote: > That's an idea, but it's messy.  I can't believe that the best way to > solve this is to repeat that chunk of code everywhere you need it.  I > could put it in some utility class, but I'm sure there must b

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread Neil
That's an idea, but it's messy. I can't believe that the best way to solve this is to repeat that chunk of code everywhere you need it. I could put it in some utility class, but I'm sure there must be a nice neat way of doing it. Neil On Oct 2, 4:02 pm, "Mark Murphy" wrote: > > Actually I ju

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread Mark Murphy
> Actually I just repeated what I was trying to do and realised I > phrased my question wrong. What I meant was how do I get the selected > (localised) value - the code I quoted gets the key as you'd expect. Um, probably with minor difficulty. The only way off the top of my head I can think of t

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread Neil
Actually I just repeated what I was trying to do and realised I phrased my question wrong. What I meant was how do I get the selected (localised) value - the code I quoted gets the key as you'd expect. On Oct 2, 3:35 pm, Neil wrote: > Yes I know that.  What I meant was that I can do this > > S

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread Neil
Yes I know that. What I meant was that I can do this SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences (this); String value = pref.getString("key", "default value"); And it will return the selected value. But how do I get the selected key? On Oct 2, 2:06 pm, "Mark Murph

[android-developers] Re: Getting the key from a ListPreference

2009-10-02 Thread Mark Murphy
> When using a PreferenceActivity to do preferences, the > PreferenceScreen can contain a ListPreference. A ListPreference has > an array of keys and an array of values. But the PreferenceActivity > only writes the values to SharedPreferences. How do I get the key of > the item selected from th