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 6209607
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T06:00:58+00:00 2026-05-24T06:00:58+00:00

I am trying to populate a Spinner in an Android dialog. When the user

  • 0

I am trying to populate a Spinner in an Android dialog. When the user clicks a button, a dialog pops up and I load the layout from an XML file. Now I am trying to populate that Spinner from a SQL query. I have searched all over and cannot figure out what the problem is. I can loop through the Cursor and add each value to an ArrayAdapter and then use that as the list for the spinner but that doesn’t come with the _id’s from the database. I have done this before using a SimpleCursorAdapter and I have even copied and pasted my old code exactly and still it isn’t working. Any help would be much appreciated.

My Dialog code:

private void displayNewInteractionDialog() {
        final Dialog dialog = new Dialog(this);
        dialog.setContentView(R.layout.mm_new_dialog);
        dialog.setTitle(R.string.mm_new_dialog_title);
        dialog.setCancelable(true);

        final Spinner spinner = (Spinner) dialog.findViewById(R.id.mm_spinner);

        DatabaseInterface db = new DatabaseInterface(this);
        db.open();

        Cursor c = db.getNames();

        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, 
            android.R.layout.simple_spinner_item,
            c,
            new String[] {DatabaseInterface.KEY_ID, DatabaseInterface.KEY_NAME}, 
            new int[] {android.R.id.text1});

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

        c.close();
        db.close();

        dialog.show();
}

Here is the code that returns a Cursor in my DatabaseInterface class:

public Cursor getNames() {
        return db.query(DATABASE_TABLE_4, new String[] {DatabaseInterface.KEY_ID, DatabaseInterface.KEY_NAME}, null, null, null, null, null);
    }

I know this will work I am just missing something apparently. I know that I could load the Spinner with the list of names from the ArrayAdapter that I stated above and also populate an array with the ID’s from the query and when the user selects an item I could just grab the corresponding one from the array of ID’s… But I know the SimpleCursorAdapter will work I just can’t seem to figure it out and I’m not giving up until I do haha. Thanks in advance for any help.

  • 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-05-24T06:00:58+00:00Added an answer on May 24, 2026 at 6:00 am

    Well looks like I am dumb haha… For some reason or another, probably from just trying numerous things and then forgetting to remove parts that I had added. I just removed c.close(); and now everything is fine. I remember adding that as I was trying to figure things out and I must’ve fixed the problem somewhere else and then didn’t realize it because this line was still in there. Since I am not actually doing anything with the Cursor other than passing it to a function, it doesn’t need to be closed. Anyhow all is good, I knew it was going to be something stupid. Like usual.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to populate an xml file into a Delphi ListView1, then group all
I am trying to populate a collection with data from a JSON file. I'm
Trying to populate a uitable from xml, xml is already parsed. for (Row* fighter
I am trying to populate an asp:Menu control using an XML file. I want
Using Android (Eclipse) I am trying to read a .csv file and dynamically populate
Trying to make a spinner that pops up a new little screen the user
I am trying to populate a spinner, but am getting an error. Here is
I have a spinner and I am trying to populate it manually in the
I am trying to populate an array with a path to a file. <?php
I am trying to populate the list li from the LoginAction on to the

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.