views:

146

answers:

4
+1  Q: 

High scores table

I am looking to add a (local, not online) high scores table to my Android app and I wanted to get some insight on the best way to approach the problem.

I have a list of users (right now being saved out to a file and read back in as an array of User objects), and the high scores need to reference this data to populate the table with the user's name and photo, etc.

For the display, I think a TableLayout would probably be my best option. I can make columns for picture, name, score, etc.

For the information itself, I'm thinking maybe a SQLite table would be the best way to organize my data? If so, then it may be worthwhile to move my user data to a SQLite table as well so I can ensure the data is cross-referenced properly.

Does anybody here have any helpful information or opinions on this? Thanks.

UPDATE: I went with the SQLite database (using two tables) and it works great! Wasn't too hard to learn and get working either. For the layout, it turns out a ListView with a custom adapter was the best way to accomplish what I wanted (more flexible than a TableLayout).

+2  A: 

I personally think it would be simpler to use a SQlite table for this. From what I can tell you only really need one table, so it might be a bit of overkill but to me it seems much simpler than dealing with file I/O.

Also with database you can more readily add extra information such as date it was recorded etc.

Adam
Thanks for the response. I think it would be better to use two tables: one for users and one for scores... but I haven't used relational databases much, so I'm not sure.
mxrider
You can use two tables if you want but it does seem like overkill. I'm currently doing a bunch of small test apps for an iphone and am using a single database of about 15 columns and 150 rows. for something like a HS table, I can't see why you'd NEED 2 tables. Sure the tables will be smaller but in this case its so small I cant seem much of a performance difference.
Adam
+2  A: 

For something as dirt simple and non-critical as a high scores list, a database feels a little like overkill to me. I'd be inclined to use a CSV file myself.

Of course, take that with a suitable grain of salt, as I don't develop on Android. If the overhead for SQLite is trivial (or if it's already on Android waiting for you to use it!), may as well use it for your data storage needs, if only to keep your code consistent.

BlairHippo
SQLite comes already as part of the Android stack, but I just haven't used databases much in general so I've been avoiding it. The other thing to note is that I probably won't ever go above 20 users on the device at any time, so speed is less of an issue.
mxrider
Then you may wish to consider using SQLite for the sake of practice. Adding database proficiency to your skillset will make you a MUCH more versatile programmer, and you gotta start somewhere. :-)
BlairHippo
+2  A: 

I haven't done a lot with Andriod but I believe you are on the right path. Using the SQLite for data will not only help keep your data structured and organized it will allow your data set to grow exponentially and you can use a common standard way to go from SQL database to Objects using a DAO pattern. I would recommend using SQLite with MyBatis. MyBatis is an Object Relational Mapping utility for java. It allows you to write sql and get back your results as java object. MyBatis

Michael Bazos
The MyBatis thing looks pretty sweet, although it may be overkill in my case. I really only have about 5 or so data fields per User (most of which are primitives), so I don't think it should be too hard to parse in and out of a SQL table.
mxrider
+1  A: 

ScoreNinja, the open-source score library for Android, might save you some time, or give you some ideas.

hgpc
I don't think I will be using this as a solution, but I may take a peek at the source to get some ideas. Thanks!
mxrider