Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8366791
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:00:05+00:00 2026-06-09T13:00:05+00:00

I’m trying to populate a spinner with a SimpleCursorAdapter. But the spinner is totally

  • 0

I’m trying to populate a spinner with a SimpleCursorAdapter. But the spinner is totally empty; it just doesn’t show items. I do not get error messages.

I’ve been trying to figure out what I am doing wrong for hours. I really hope you can help me.

This is the onCreate function in my activity:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.insert);

    spinner     = (Spinner)     findViewById(R.id.spinner);
    fillSpinner();
}

This is the function that should populate the spinner:

private void fillSpinner() {
        Db = new DbAdapter(this);
        Db.open();
        final Cursor cursor = Db.getCats(true,true);

        Log.d("fillSpinner","cursor.getCount: "+cursor.getCount()+" / cursor.getColumnCount: "+cursor.getColumnCount());//returns 8 and 4

        String[] from = new String[]{DbAdapter.KEY_NAME};
        int[] to = new int[]{android.R.id.text1};

        SimpleCursorAdapter adapter =
                new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor, from, to);

        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

        spinner.setAdapter(adapter);

        //...   

        cursor.close();
        Db.close();
    }

And this is my getCats() function in my DbAdapter class:

public Cursor getCats(boolean times, boolean adapter) {

        String id = KEY_ID;
        if(adapter){
            id = KEY_ID +" "+_ID;
        }

        String columns = id+", "+KEY_NAME;
        if(times){
            columns+=", "+KEY_START+", "+KEY_END;
        }
        return Db.rawQuery("SELECT "+columns+" FROM "+CATS_TABLE+" ORDER BY "+KEY_ID+" ASC", null);
    }

And my constants:

private static final String CATS_TABLE  = "cats";

public static final String KEY_ID       = "id";
public static final String KEY_NAME     = "name";
public static final String KEY_START    = "start";
public static final String KEY_END      = "end";

public static final String _ID          = "_id";

Thanks in advance!

Yellos

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T13:00:07+00:00Added an answer on June 9, 2026 at 1:00 pm

    Don’t close the cursor.

    The cursor must remain open while you use the spinner. After you call the cursor let the system handle closing it by calling startManagingCursor. It will close it when you are done w/o you having to worry about it.

    final Cursor cursor = Db.getCats(true,true); 
    this.startManagingCursor(cursor);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to select an H1 element which is the second-child in its group

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.