How can I display a particular array of items from a database (SQLServer) in a Spinner of Android?
2 Answers
You provide data to your Spinner by way of a SpinnerAdapter. The adapter can be backed by a simple array, or by a database cursor, or whatever you like...
If you really mean Microsoft SQL Server — as in an external database — you would need to have some sort of web-service or other internet-based protocol to let you retrieve the data from the remote server. Then you could bind the data yourself to an ArrayList or Cursor.
Alternatively, if you mean local database storage such as an SQLite DB, then it's even easier as you don't need to query over the network.
Essentially you can just follow any ListView tutorials as the process is pretty much the same — in your case you just want to call Spinner.setAdapter() rather than ListView.setAdapter().
In fact, there is a Spinner tutorial on the Android developers' site!
1 Comment
jTDS could be what you are looking for, a 100% pure java JDBC driver for Microsoft SQLServer. Then you can implement an Adapter to retrieve the data.