views:

38

answers:

1

I'm looking for a good way to manage multiple SharedPreference files. Basically the user should be able to create, edit, and delete the preference files and then select the one they want from a spinner.

What I'm trying to figure out is how do I find all of the preference files that the app has? Is there a way to scan the directory and return the names of all of the preference files?

I'm thinking that once I get a lits of all of the names I could create a string array with all of the names and feed it to the spinner.

Thanks for the help!

+1  A: 

I'd use a single SharedPreferences object + an array of preference keys that would get prefixed for different configurations + a simple helper class.

alex
I'm not sure I understand completely what you are saying. I'll try to explain what I want to do a little better. Let's say it was cars. The user would add a car, say Dodge Challenger, have a string for its name and some numerical values for its horsepower, top speed, etc. that the user could enter. That is the kind of data I want to store and retrieve. Then the user could have any number of other cars as well. If I store them all in the same preference file, how do I know X horsepower goes with X car, and not Y car?
Matt
Matt, you really need a SQLite db with a table for cars (as per example) and another one for car characteristics. SharedPreferences are meant for simple key-value stuff.
alex
Thanks, I've been pouring over the data storage methods and I've kept on skipping over the SQLite stuff because I'm unfamiliar with it. I guess I've got some reading to do!
Matt
Just following up. I have my app writing to the SQLite database. And I have it verified by pulling the database file with DDMS and using a database browser on my desktop. Looks like this will be the perfect solution to my problem, thanks!
Matt