Individual Preferences for each item in a ListView?

自作多情 提交于 2019-12-11 02:34:23

问题


I'm creating my first android app (or attempting to anyway) and i have a question i can't seem to find the answer to.

I would like to allow users to enter a separate set of preferences for each item in a list view. I have the PreferenceScreen working, but it maintains the same preferences for every item (i.e. changing 1 item results in changes to all others as well).

To give a more detailed example: Say i have a list of cars: * Car 1 * Car 2 * Etc...

I would like to be able to click on "Car 1" and get a PreferencesScreen to specify "Make", "Model", "Color" for just that car, instead of having those entries stored globally for the whole app.

Is this possible?

Thanks for your help!

//N


回答1:


Solved it!!

For any wondering, the solution is that you must call

getPreferenceManager().setSharedPreferenceName(value) with a value unique to the item you'd like to modify the preferences for (in my case, i used the ListView position) prior to calling addPreferencesFromResource.




回答2:


getPreferenceManager() deprecated on api 11

Now with honeycom and ICS the method getPreferenceManager() is deprecated. Do you know how to do that with the new (PreferenceFragment + Headers)?

Thanks men! It works perfect in earlier versions!

UPDATE: Up to api level 11 is the same method but you have to call it on a Fragment, not on activity.



来源:https://stackoverflow.com/questions/3217720/individual-preferences-for-each-item-in-a-listview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!