Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
Zero The Hero
Jan 7, 2009

Hey guys, looking for some advice here. I'm trying to do some type of persistent data storage in my app, and after looking around, I decided a FileOutputStream( http://developer.android.com/reference/java/io/FileOutputStream.html ) would probably be best for me. Right now, all I have is a LinearLayout with a series of CheckBoxes. I just need an efficient way to save the data, which is the only way a checklist is ever going to be useful.

As it is right now, my xml file contains all the CheckBoxes, and my java file is pretty clean. I know I'm going to need to read in the data and set the initial states of all the CheckBoxes in the onCreate() function and save in the onPause() and onStop() functions. I assume I could, in each of these functions, address each CheckBox by id and update the info that way. But that's not a good solution, since every time I decided to add a new CheckBox to the cheklist, I'd have to update the layout file, as well as three separate functions in the java file. I was hoping there would be a way to just read every box in sequence and write the whole thing to a file. My C background is telling me to throw them all in a struct and read/write the struct to and from a file each time, but something tells me that's just not going to work here.

Adbot
ADBOT LOVES YOU

Zero The Hero
Jan 7, 2009

Doctor w-rw-rw- posted:

You should be able to hook checkboxes up straight into SharedPreferences. I could be wrong, since I haven't done anything like that in a while, and it might have been a function of a PreferencesScreen, but you should probably use SharedPreferences regardless, if it's a mostly static set of checkboxes. Otherwise I dunno.

I'm looking at this tutorial: http://developer.android.com/guide/topics/data/data-storage.html#pref
This looks easy, and it would certainly work for storing a lot of binary data, but I'm not sure how this streamlines the process. It looks like I'd still have to address each CheckBox individually, I'm looking for a way to access them through a loop, or something, or together as one entire unit. Or am I just missing something about how preferences work?

Zero The Hero
Jan 7, 2009

Lutha Mahtin posted:

SQLite, man.

Well, I looked into that. I was hoping to avoid it, partially because it's been a while since I used databases for anything, and partially because I haven't actually figured out all the fields it would need, and I'm not sure how much of a hassle it would be to update(see first reason). But now I'm looking into ListViews and I think it would make using SQLite a lot easier(and vice versa).

Not entirely sure, though. This is the link I'm using: http://developer.android.com/guide/topics/ui/layout/listview.html .
It looks like it can read and display an unspecified amount of data, I just have to make sure it can display that data as checkboxes. And figure out how the loader works.

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply