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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:25:02+00:00 2026-06-09T14:25:02+00:00

I have spinner which I populate from SQLite database. But I want to populate

  • 0

I have spinner which I populate from SQLite database. But I want to populate it from string-array:

<string-array name="category">
    <item name="accommodation">Accommodation</item>
    <item name="automobile">Automobile</item>
    <item name="credit cards">Credit Cards</item>
    <item name="donations">Donations</item>
    <item name="entertainment">Entertainment</item>
    <item name="food">Food</item>
</string-array>

where name I take from SQLite table.
I have method which retrieve name from database:

public Cursor getAllCategory() {
    mDB = dbHelper.getReadableDatabase();
    return mDB.query(CATEGORY_TABLE_NAME, null, null, null, null, null,null);
}

And in my program I use these names:

// spinner
        catSpinner = (Spinner) view.findViewById(R.id.category_spinner);
        cursor = adapter.getAllCategory();
        String[] from = new String[] { DataAdapter.CATEGORY_COL_NAME };
        int[] to = new int[] { android.R.id.text1 };
        SimpleCursorAdapter catAdapter = new SimpleCursorAdapter(
                getActivity(),
                android.R.layout.simple_spinner_dropdown_item, cursor,
                from, to, 0);
        catAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        catSpinner.setAdapter(catAdapter);

But I want use names from database, but value that ​​responding to these names(string.xml) use from string-array

How I can do this? I want to do this to avoid changing database when I change localization.

  • 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-09T14:25:04+00:00Added an answer on June 9, 2026 at 2:25 pm

    Try this.For getting data into the spinner you have to use SimpleCursorAdapter which is given below.

      // This is your method of database class which returns cursor
     Public Cursor getAllNames(){
       return mDb.query(table_name, new String[]{KEY_ROWID, KEY_TITLE}, null, null, null, null, null );
    }
    

    And use this method in spinner to get items(i.e. Name).

     Cursor c = mDbHelper.getAllNames();
     startManagingCursor(c);
    
      String[] from = new String[]{your_name};
    // create an array of the name which you want to bind our data to
      int[] to = new int[]{android.R.id.text1};
    
      // This is your simple cursor adapter
       SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, c, from, to );
       adapter.setDropDownViewResource( android.R.layout.simple_spinner_dropdown_item );
    
       Spinner s = (Spinner) findViewById( R.id.unique_id ); // This is your spinner
       s.setAdapter(adapter); // Set it to the adapter
    

    Hope this helps. 🙂

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

Sidebar

Related Questions

I have a spinner witch is populated from database, when I select an item
I have a spinner that show my data list from a database SQLite.. I
I have a listview which loads its data from sqlite database. Each row in
Hi i have an android spinner populated from and array that i want to
So, at the moment I have a spinner which is populated from a database
I have a spinner which is populated from the database. This in turn is
i have an array which is populated in the spinner adapter. now i wanna
I have an application, which has a Spinner that I want populated with some
I got a Spinner element which I populate with data from a Cursor using
So I want to populate a Spinner with a String like All, followed by

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.