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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:47:25+00:00 2026-05-26T03:47:25+00:00

I am new in android. I need to fill the spinner from SQLite database.

  • 0

I am new in android. I need to fill the spinner from SQLite database.
my layout >> main.xml contains

<Spinner 
            android:id="@+id/cmbLocations"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:drawSelectorOnTop="true"
            android:prompt="@string/location_prompt"
        />

<EditText android:id="@+id/text1" android:layout_width="300dp" android:layout_height="wrap_content"/>

I have a public function which returns the locations:

public static final String KEY_ROWID = "_id";
public static final String KEY_LOCATION = "location";

public Cursor GetLocations()
    {
        return db.query(DATABASE_TABLE, 
                new String[] 
                { 
                    KEY_ROWID, // "_id"
                    KEY_LOCATION // "location"
                }, null, null, null, null, null);
    }

The code which is populating the spinner is :

    Spinner cmbLocations = (Spinner) findViewById(R.id.cmbLocations);
    DBAdapter db = new DBAdapter(this);
    db.open();

    Cursor cur = db.GetLocations();
    String[] from = new String[]{"_id","location"};
    int[] to = new int[]{R.id.text1};// I don't know that why text1 is required here

    startManagingCursor(cur);
    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item, cur, from, to); 
                    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
cmbLocations.setAdapter(adapter);
db.close();

The issue i am facing is that the spinner controls shows EMPTY locations. For example if i have two locations, Location1 & Location2. The spinner will show two EMPTY locations. If i have 3 locations the spinner will show three EMPTY locations.

Thanks in advance for your 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-26T03:47:26+00:00Added an answer on May 26, 2026 at 3:47 am

    Try using:

    String[] from = new String[]{"_id","location"};
        int[] to = new int[]{R.id.text1,R.id.text2};// I don't know that why text1 is required here
    

    int[] to is for placing the values from the cursor,you defined in from.. For example,you are fetching _id and location then you would have to specify its destination,here it might be textview.

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

Sidebar

Related Questions

i am new to java and android. I need some help with my main.xml
I am working on a new module of Email application in android. My main.xml
I'm new to Android so not very good with GUi layout yet. I'm building
I need some help. In my android app I have a ViewFlipper that contains
I need your help. I'm really new to Android, developing in Eclipse with the
I have a layout like this in xml format. But I need to do
I have the following layout for my ImageView : <?xml version=1.0 encoding=utf-8?> <LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
Currently, my linearlayout is set as GONE in my main.xml . I need to
I have a ViewFlipper defined that contains 3 views... <?xml version=1.0 encoding=utf-8?> <ViewFlipper xmlns:android=http://schemas.android.com/apk/res/android
The new Android 2.1 SDK (version 7) has a new class called SignalStrength: http://developer.android.com/reference/android/telephony/SignalStrength.html

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.