|
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.
|
# ¿ Aug 10, 2012 18:56 |
|
|
# ¿ May 3, 2024 03:14 |
|
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?
|
# ¿ Aug 11, 2012 03:25 |
|
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.
|
# ¿ Aug 15, 2012 04:19 |