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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T11:06:27+00:00 2026-05-18T11:06:27+00:00

i’m trying to connect query a database and display the results in a Spinner.

  • 0

i’m trying to connect query a database and display the results in a Spinner. below is what i have so far. unfortunately the spinner only displays the last row that should have been returned from the query. so from the example above, only “Elvis Presley” shows up in the list. i’ve tried using “Cursor.moveToFirst()” (as you can see) but that doesn’t do it.

i realized that i rebuild and update the database everytime i open it. i’m doing this on purpose for now.

package com.conceptualsystems.android4api.sms;

import java.util.List;
import java.util.ArrayList;
import java.util.LinkedList;

import android.app.Activity;
import android.app.Dialog;
import android.app.AlertDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.ContentValues;
import android.database.Cursor;
import android.database.sqlite.SQLiteOpenHelper;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;
import android.view.Window;
import android.view.View;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.EditText;
import android.widget.Toast;
import android.widget.SimpleCursorAdapter;


public class smsActivity extends Activity
{
    private static class smsDbOpenHelper extends SQLiteOpenHelper {

        smsDbOpenHelper(Context context) {
            super(context,smsDbSchema.DATABASE_NAME, null, smsDbSchema.DATABASE_VERSION);
        }

        @Override
        public void onCreate(SQLiteDatabase db) {
            db.execSQL(smsDbSchema.CustomerSchema.CREATE_TABLE);
            db.execSQL(smsDbSchema.ProductSchema.CREATE_TABLE);
        }

        @Override
        public void onOpen(SQLiteDatabase db) {
            //open db
            db.execSQL("DROP TABLE IF EXISTS " + smsDbSchema.CustomerSchema.TABLE_NAME);
            db.execSQL("DROP TABLE IF EXISTS " + smsDbSchema.ProductSchema.TABLE_NAME);
            this.onCreate(db);
        }

        @Override
        public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
            //upgrade db
        }
    }

    private smsDbOpenHelper mDbHelper;
    private SQLiteDatabase mDb;



    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);

        mDbHelper = new smsDbOpenHelper(getApplicationContext());
        mDb = mDbHelper.getReadableDatabase();

        //fill customer table with some fake data
            ContentValues cv = new ContentValues();
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Charles Keith Gilliam");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Jarrod Martin");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "John Lennon");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Sammy Hagar");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "David Lee Roth");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Keith Richards");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Steven Tyler");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Brent Michaels");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Eddie Veder");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Kurt Cobain");
            cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Elvis Presley");
            cv.put(smsDbSchema.CustomerSchema._ID, "0298437598745");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
            mDb.insert(smsDbSchema.CustomerSchema.TABLE_NAME, null, cv);

            //cv.

        setScreen(R.layout.inbound);

        Spinner custSpn = (Spinner)findViewById(R.id.cust_spn);
        Cursor custCur = null;
        try {
            custCur = mDb.query(smsDbSchema.CustomerSchema.TABLE_NAME, null, null, null, null, null, null);
        } catch(Exception e) {
            Log.e("smsdb", e.toString());
        }
        custCur.moveToFirst();
        startManagingCursor(custCur);
        SimpleCursorAdapter qc = new SimpleCursorAdapter(
            this,
            android.R.layout.simple_spinner_item,
            custCur,
            new String[] {smsDbSchema.CustomerSchema.COLUMN_NAME},
            new int[] {android.R.id.text1}
        );
        qc.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        custSpn.setAdapter(qc);

        Spinner prdSpn = (Spinner)findViewById(R.id.prd_spn);
        Cursor prdCur = null;
        try {
            prdCur = mDb.query(smsDbSchema.ProductSchema.TABLE_NAME, null, null, null, null, null, null);
        } catch(Exception e) {
            Log.e("smsdb", e.toString());
        }
        prdCur.moveToFirst();
        startManagingCursor(prdCur);
        qc = new SimpleCursorAdapter(
            this,
            android.R.layout.simple_spinner_item,
            prdCur,
            new String[] {smsDbSchema.ProductSchema.COLUMN_NAME},
            new int[] {android.R.id.text1}
        );
        qc.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        prdSpn.setAdapter(qc);

        mDb.close();
    }

    public void setScreen(int resource) {
        setContentView(resource);

        if(resource==R.layout.inbound) {
            //setup main entry screen
            final Button transmit = (Button)findViewById(R.id.transmit_btn);
            final Button clear = (Button)findViewById(R.id.clear_btn);
            transmit.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {
                    // transmit data ////////
                    /////////////////////////
                }
            });
            clear.setOnClickListener(new View.OnClickListener() {
                public void onClick(View v) {

                    //clear fields
                }
            });
        }
    }
}
  • 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-18T11:06:28+00:00Added an answer on May 18, 2026 at 11:06 am

    You are putting values in Content Values.

    ContentValues cv = new ContentValues();
    cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Charles Keith Gilliam");
    ..
    ..
    ..
    

    Anf finally u write a insert statement. So, to my understanding essentially u put only one value in the ContentValues since others are overwritten.

    You can also pull the db file using DDMS and open using SQLite browser to make that all entires are there in the DB

    You should try inserting each content value lik this. Pls try this so that all entries are made in the db.

    cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Charles Keith Gilliam");
    cv.put(smsDbSchema.CustomerSchema._ID, "7585684317298");
    mDb.insert(smsDbSchema.CustomerSchema.TABLE_NAME, null, cv);
    
    cv.put(smsDbSchema.CustomerSchema.COLUMN_NAME, "Jarrod Martin");
    cv.put(smsDbSchema.CustomerSchema._ID, "0298437598745");
    mDb.insert(smsDbSchema.CustomerSchema.TABLE_NAME, null, cv);
    
    • 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
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have a view passing on information from a database: def serve_article(request, id): served_article
I have a reasonable size flat file database of text documents mostly saved in
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
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
this is what i have right now Drawing an RSS feed into the php,

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.