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?
+1
A:
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.
CommonsWare
2010-05-03 22:06:19