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

  • Home
  • SEARCH
  • 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 7784199
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:03:24+00:00 2026-06-01T20:03:24+00:00

I have a SQLite query that returns a Cursor . I want to add

  • 0

I have a SQLite query that returns a Cursor. I want to add some extra rows to the Cursor by implementing a MatrixCursor(to try to keep the first item of real data from automatically selected when clicked). Then I want to map them to a SimpleCursorAdapter. I kept reading the posts(and codes) but still remain fuzzy to me how to code it to my existing code listed below.

    Cursor cursor = myDB.query(DATABASE_TABLE_NAME, resultColumns, whereClause,
            whereArgs, null, null, null, null);

    // Create Spinner View object from layout resource
    Spinner spinner = (Spinner) findViewById(R.id.spinner);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
            android.R.layout.simple_spinner_item, // Use a template
                                                  // that displays a
                                                  // text view
            cursor, // Give the cursor to the adapter
            new String[] {"ename"}, // Map the NAME column in the
                                                 // people database to...
            new int[] {android.R.id.text1}); 

    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner.setAdapter(adapter);
    spinner.setOnItemSelectedListener(new MyOnItemSelectedListener());
  • 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-01T20:03:25+00:00Added an answer on June 1, 2026 at 8:03 pm

    If you want to build a MatrixCursor from a simple Cursor you’ll have to parse the entire initial Cursor and append the rows you want:

    //...
        MatrixCursor mc = new MatrixCursor(resultColumns);
        // add extra rows, this will probably not work if you want to insert them
        // between the initial cursor rows because of the _id column that need autoincrement values
        mc.addRow(new Object[] { new Long(-2), "Extra name1" }); 
        mc.addRow(new Object[] { new Long(-1), "Extra name2" });
        // I don't know what your cursor holds, I assumed you have the _id column(long value)
        // and a name(String value)
        int size = cursor.getCount();
        for (int i = 0; i < size; i++) {
            cursor.moveToPosition(i);
                mc.addRow(new Object[] {
                cursor.getLong(cursor.getColumnIndex(/*the _id column*/)),
                cursor.getString(cursor.getColumnIndex(/* the name column(ename?!?)*/)) });
        }
        SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,
                android.R.layout.simple_spinner_item, mc, new String[] {"ename"}, new int[] {android.R.id.text1}); 
    //...
    

    If you’re doing this just to avoid the OnItemSelectedListener from firing when the Spinner is shown, maybe you could have another approach. For example in your listener:

        //boolean status = true; flag in MyOnItemSelectedListener
    
        @Override
        public void onItemSelected(AdapterView<?> parent, View view,
                int position, long id) {
            if (status) {
                status = false;// this is the first listener trigger so you probably want to ignore it
                return;
            }
            // do stuff here
        }
    

    Note: I don’t know how good is the above solution. If you look there are probably much better solution to this Spinner related issue.

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

Sidebar

Related Questions

I'm trying to query my SQLite DB for all rows that have a particular
I have an SQLite query that, potentially, returns thousands of records. I need to
I have some codes read the query results from sqlite: while (sqlite3_step(statement) == SQLITE_ROW)
i'm trying to get a query that returns rows only with a specified name,
I have table in sqlite that contain only one record and I want to
i have a method that return a ArrayList from a sqlite query, only a
I have a description column in my SQLite database that contains some text to
I have an sqlite union query: SELECT term,abstract, termid, nterm FROM (SELECT term, subterm,
I have a pretty long sqlite query: const char *sql_query = SELECT statuses.word_id FROM
I have to execute the following query in Android SQLite UPDATE player SET rank=rank+1

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.