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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:29:55+00:00 2026-06-13T15:29:55+00:00

In my Android App I hava a layout with to Spinners. What I want

  • 0

In my Android App I hava a layout with to Spinners. What I want to do is given a selected item from the first spinner, fill up the second one.

The first spinner is filled up from a cursor (result of a database query) like this:

Spinner combo1 = (Spinner) findViewById(R.id.combo1);
mDbH.open();
Cursor c1 = null;
c1 = mDbH.consulta4();
startManagingCursor(c1);
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this,android.R.layout.simple_spinner_item,c1,new String[] {"nombre"},new int[] {android.R.id.text1});
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
combo1.setAdapter(adapter);

This works fine! The problem comes inside my event listener:

combo1.setOnItemSelectedListener(new OnItemSelectedListener(){
    public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
        String est = String.valueOf(combo1.getSelectedItem());
        int idEst = (int) id;
        Log.e("est",est);
        Log.e("idEst",""+idEst);
        mDbH.open();
        Cursor c = null;
        c = mDbH.consulta5(idEst,est);
        SimpleCursorAdapter adapter2 = new SimpleCursorAdapter(getApplicationContext(),android.R.layout.simple_spinner_item,c,new String[] {"nombre"},new int[] {android.R.id.text1});
        adapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        combo1.setAdapter(adapter2);
    }

    public void onNothingSelected(AdapterView<?> arg0) {}

});

Because, in the LogCat the line Log.e(“est”,est); shows this:

10-25 09:48:50.390: E/est(3462): android.database.sqlite.SQLiteCursor@40625638

And of course, that value is not in my database and the second cursor is empty and the spinner doesn’t fill up with anything!! So, this is my question, how do you get the item selected of a spinner when is filled up from a database? I also tried out:

String est = combo1.getSelectedItem().toString();

and

String est = parentView.getItemAtPosition(position).toString();

but the result is the same!! Am I doing something wrong? Please help!

Thanks!

  • 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-13T15:29:57+00:00Added an answer on June 13, 2026 at 3:29 pm

    Since your Spinner was filled out using a SimpleCursorAdapter, getItemAtPosition & getSelectedItem will return a Cursor reference. Use:

    Cursor c=(Cursor) combo1.getSelectedItem();
    String est=c.getString(c.getColumnIndex("nombre");
    

    Same works for getItemAtPosition(position)

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

Sidebar

Related Questions

In Android app i want to return JSONObject from doInBackground() method to onPostExecute() method.
My android app has 4 tabs. In one tab it loads twitter data from
The android app reads from database but doesnt write anything to DB, the app
i am learning to program mobile aplications on Android. My first app is a
My android app is opened from another app. I know how to return results
My android app get a crash when init a tabhost.But the crash log from
My Android app is reading and writing to a local SQLite DB from a
My android app fetches a JSON structure from the net. It's somewhat large, maybe
My Android app is configured to work on landscape mode only, so I want
My Android app is a client that fetchs datas from a Web Service and

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.