I am using SQLite to store school classes. I want to fill in a Spinner with the classes that get stored in the database. How would I grab all the classes in the DB and load them into a spinner?
4
-
Is SQLite running on Android ?Romain Hippeau– Romain Hippeau2010-05-03 18:30:24 +00:00Commented May 3, 2010 at 18:30
-
Yea the SQLite is running on the android.Aarron– Aarron2010-05-03 19:00:11 +00:00Commented May 3, 2010 at 19:00
-
You don't want to put more than a handful of strings into a spinner or it will quickly become unusable. If you have so many classes that you need to store them in a database, it may not be a good fit. On the other hand, if you only have a few, perhaps it is enough to just use preferences: developer.android.com/intl/zh-CN/guide/topics/data/…RickNotFred– RickNotFred2010-05-03 21:17:57 +00:00Commented May 3, 2010 at 21:17
-
First off, thanks for the responses. It will only be a few classes and I am using a database just because that was the first thing I found for storage and I don't have time to go back and change all my code for the preferences. So is there a way to query the classes out of the database and add them to the spinner?Aarron– Aarron2010-05-03 21:49:43 +00:00Commented May 3, 2010 at 21:49
Add a comment
|
1 Answer
Step #1: Use query() or rawQuery() to get a Cursor with the results of a query on your database.
Step #2: Wrap the Cursor in a CursorAdapter, set to populate rows with your database results.
Step #3: Attach the CursorAdapter to the Spinner.
Here is a sample project showing using a CursorAdapter with a database query, but for a ListView. Here is a sample project showing using a CursorAdapter with a Spinner, but from a query against a content provider, not a database.