Using a Spinner with a SimpleCursorAdapter

I have an activity which has a Spinner widget to display categories. Initially I was using an ArrayAdapter to populate the the spinner as in the following code

private static final String[] arrayCategories = {

mCatSpinner = (Spinner) findViewById(;
ArrayAdapter<String> catAdapter = new ArrayAdapter<String>(this, R.layout.track_category_item, arrayCategories);

This works fine, and the spinner displays the first array item by default if no selection is made. It does show the selected item when an item is actually selected

But now I want to use a SimpleCursorAdapter to pull the list contents from a db. So I changed it to

SimpleCursorAdapter scaCategories = new SimpleCursorAdapter(this, R.layout.track_category_item,cCategories,new String[] {DBAdapter.KEY_CATEGORIES_NAME},new int[]{});
mCatSpinner = (Spinner) findViewById(;

This populates the dropdown, but it does not display the first item in the spinner. Even if selected, it does not show the selected item.

I tried to setSlection to the first item using

if(mCatSpinner.isSelected() != true) {

but it didn't work

What is wrong?

Asked by: Alina268 | Posted: 25-01-2022

Answer 1

Ok, it would help if I specified the widget id in the layout xml. <:(

Answered by: Kelvin447 | Posted: 26-02-2022

Similar questions

database - How to text filter an Android ListView backed by a SimpleCursorAdapter?

I have a ListView that is backed by a SimpleCursorAdapter. I'd like to be able to filter the list like you would a contacts list, just by typing, and I came across the textFilterEnabled() Problem is, I couldn't see how to get it to work with a SimpleCursorAdapter. Is this even possible? If so, how is it done?

how to set the simplecursoradapter to a listview in android?

i have to set the simpleCursorAdapter into a listView. how can i achieve that? thanks.

sqlite - Android: Filtering a SimpleCursorAdapter ListView

Right now, I'm running into issues trying to implement a FilterQueryProvider in my custom SimpleCursorAdapter, since I'm unsure of what to do in the FilterQueryProvider's runQuery function. In other words, since the query that comprises my ListView basically gets the rowID, name, and a third column from my databases's table, I want to be able to filter the cursor based on the partial value of the name column. ...

android - Computation on db data then list them using either SimpleCursorAdapter or ArrayAdapter

I juststarted programming in android a few weeks ago, so I am not entirely sure how to deal with listing values. Please help me out! I have some questions regarding displaying data sets from db in a list. Currently I have a cursor returned by my db points to a list of rows and I want display 2 columns values in a single row of the list. The row xml looks like this: &lt;TextView android:id="@+id/text1" ...

android - Impossible to close Cursor when setting to SimpleCursorAdapter

Im performing certain database operations after which I attach Cursor to the SimpleCursorAdapter for display List on my ListActivity. If I close the cursor in finally block (or anywhere after the code below), nothing is displayed in the list SimpleCursorAdapter scAdapter = new SimpleCursorAdapter(this, R.layout.list_row, cursor, new String[] { Constants.KEY_TITLE }, new int[] {

android - Jerky Scrolling when using SimpleCursorAdapter with ListView

I'm getting some very jerky scrolling while using the code below to create a ListView from a Cursor. Is there something I'm doing wrong, or any way to improve the performance of this ListView? bookmarksListView = (ListView)findViewById(; bookmarksDbCursor = bookmarkStore.getCursor(); startManagingCursor(bookmarksDbCursor); ...

android - SimpleCursorAdapter crashes within an Activity

I'm trying to create an activity with a list that uses a SimpleCursorAdapter, but it just won't work. I'm creating the cursor correctly because when I make it print out text, all the values are printed and I know there's nothing wrong with the SimpleCursorAdapter class because when I used it with the image content provider, it displayed correctly. However, when I try to put the two together, my ap...

Android SimpleCursorAdapter and Database Update

I just started with Android development and love it so far. To get some experience, I am writing a little todo application. In my database I have a state for a todo item, represented as int. I use a checkbox in a list view to represent this state. To bind the data to the view, I use a subclass of SimpleCursorAdapter. I add an onClickListener to the checkbox that updates the state in the database for the used list item. The...

sqlite - Android SimpleCursorAdapter / ListView issue

I have a problem displaying the results of an sql query into a ListView via SimpleCursorAdapter. This is my query: String sql = "" + "SELECT (Clients.firstname || \" \" || Clients.surname) AS client_name, " + "Visits._id, " + "Status.status, " + "strftime('%H:%M',time(sql_start_date,'unixepoch')) as start_time, " + "strftime('%H:%M',time(sql_end_date,'unixepoch')) as end...

java - onClick inside ListActivity using SimpleCursorAdapter

I've got a class that creates a list from a DB using SimpleCursorAdapter. I want to add an onClick event to each item in the list but I don't know where to place the code. Any help?

Still can't find your answer? Check out these communities...

Android Google Support | Android Community | Android Community (Facebook) | Android