1

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 ? Commented May 3, 2010 at 18:30
  • Yea the SQLite is running on the android. Commented 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/… Commented 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? Commented May 3, 2010 at 21:49

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.