[android-developers] Re: Is it possible to have dynamicly generated keys in a preferance screen?

2011-02-06 Thread ThomasWrobel
Sorry I wasn't clear; I did try it and it doesnt work. It always says
"no value set" however, and no changes are remembered
in the interface.

The changes are being made by the interface too, not programaticly so
I shouldn't need that commit.

I'm just wondering if something strange happens as soon as I change
that keys name :-/

On Feb 6, 9:35 pm, TreKing  wrote:
> On Sat, Feb 5, 2011 at 8:58 PM, ThomasWrobel  wrote:
> > Do I have to manualy commit?
>
> Possibly. Try it, see what happens.
>
> > or set the persistance to true? (isn't that default).
>
> The preferences will save their values automatically when the user makes a
> selection. If you manually setting the values, you normally do an
> Editor().commit() call once you're done making changes.
>
> ---­--
> TreKing  - Chicago
> transit tracking app for Android-powered devices

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Is it possible to have dynamicly generated keys in a preferance screen?

2011-02-06 Thread Kostya Vasilyev

I'm doing this in my current project, although in a slightly different way.

In my case, a subclass of PreferenceActivity is invoked for a particular 
object, each of which has uniform properties that need to be stored 
independently of properties for other objects of that class. In other 
words, each object instance gets its own preference values.


The code is:

class ItemOptionsActivity extends PreferenceActivity {

onCreate:

String prefsName = "item_" + itemId;
PreferenceManager prefManager = getPreferenceManager();
prefManager.setSharedPreferencesName(prefsName);

}

This is it for the preference activity - the above code makes it 
automatically load and store preference values in a separate file, keyed 
by item Id.


To access object-specific preferences I do this:

String prefsName = "item_" + itemId;
SharedPreferences prefs = mContext.getSharedPreferences(prefsName, 
Context.MODE_PRIVATE);


The rest is boilerplate.

-- Kostya

07.02.2011 0:08, ThomasWrobel пишет:

Sorry I wasn't clear; I did try it and it doesnt work. It always says
"no value set" however, and no changes are remembered
in the interface.

The changes are being made by the interface too, not programaticly so
I shouldn't need that commit.

I'm just wondering if something strange happens as soon as I change
that keys name :-/

On Feb 6, 9:35 pm, TreKing  wrote:

On Sat, Feb 5, 2011 at 8:58 PM, ThomasWrobel  wrote:

Do I have to manualy commit?

Possibly. Try it, see what happens.


or set the persistance to true? (isn't that default).

The preferences will save their values automatically when the user makes a
selection. If you manually setting the values, you normally do an
Editor().commit() call once you're done making changes.

---­--
TreKing  - Chicago
transit tracking app for Android-powered devices



--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en


Re: [android-developers] Re: Is it possible to have dynamicly generated keys in a preferance screen?

2011-02-06 Thread Thomas Wrobel
Thanks for the tip, that actualy looks like a much more neater way of
doing it then trying to manualy change all the keys. I'll try to adapt
that for my own requirements, shouldn't be too hard.

-Thomas


~~
Reviews of anything, by anyone;
www.rateoholic.co.uk
Please try out my new site and give feedback :)



On 6 February 2011 22:18, Kostya Vasilyev  wrote:
> I'm doing this in my current project, although in a slightly different way.
>
> In my case, a subclass of PreferenceActivity is invoked for a particular
> object, each of which has uniform properties that need to be stored
> independently of properties for other objects of that class. In other words,
> each object instance gets its own preference values.
>
> The code is:
>
> class ItemOptionsActivity extends PreferenceActivity {
>
> onCreate:
>
> String prefsName = "item_" + itemId;
> PreferenceManager prefManager = getPreferenceManager();
> prefManager.setSharedPreferencesName(prefsName);
>
> }
>
> This is it for the preference activity - the above code makes it
> automatically load and store preference values in a separate file, keyed by
> item Id.
>
> To access object-specific preferences I do this:
>
> String prefsName = "item_" + itemId;
> SharedPreferences prefs = mContext.getSharedPreferences(prefsName,
> Context.MODE_PRIVATE);
>
> The rest is boilerplate.
>
> -- Kostya
>
> 07.02.2011 0:08, ThomasWrobel пишет:
>>
>> Sorry I wasn't clear; I did try it and it doesnt work. It always says
>> "no value set" however, and no changes are remembered
>> in the interface.
>>
>> The changes are being made by the interface too, not programaticly so
>> I shouldn't need that commit.
>>
>> I'm just wondering if something strange happens as soon as I change
>> that keys name :-/
>>
>> On Feb 6, 9:35 pm, TreKing  wrote:
>>>
>>> On Sat, Feb 5, 2011 at 8:58 PM, ThomasWrobel  wrote:

 Do I have to manualy commit?
>>>
>>> Possibly. Try it, see what happens.
>>>
 or set the persistance to true? (isn't that default).
>>>
>>> The preferences will save their values automatically when the user makes
>>> a
>>> selection. If you manually setting the values, you normally do an
>>> Editor().commit() call once you're done making changes.
>>>
>>>
>>> ---­--
>>> TreKing  - Chicago
>>> transit tracking app for Android-powered devices
>
>
> --
> Kostya Vasilyev -- WiFi Manager + pretty widget --
> http://kmansoft.wordpress.com
>
> --
> You received this message because you are subscribed to the Google
> Groups "Android Developers" group.
> To post to this group, send email to android-developers@googlegroups.com
> To unsubscribe from this group, send email to
> android-developers+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/android-developers?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en