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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T07:24:17+00:00 2026-05-31T07:24:17+00:00

Is there a simple way to get the user’s selection (the string value) from

  • 0

Is there a simple way to get the user’s selection (the string value) from a spinner ? I am trying to avoid setting a listener on it and writing an onItemSelected() method, because I don’t need anything to happen when the user makes the selection. Rather, I’m trying to set up a button click to capture the selection and send it in a bundle to another activity. My spinner is being filled by a cursor. Here is my code, and it crashes on the line:

String choice = this.adapter.getItem(index).toString();

The code:

public class MainActivity extends BaseActivity
{   
static final String TAG = "MainActivity";
static final String[] FROM = {CreateDB.C_CATEGORY};
static final int[] TO = {android.R.id.text1};
CreateDB dbBuilder;
SQLiteDatabase database;
Cursor cursor;
SimpleCursorAdapter adapter;
Spinner spinnerLocal;

@Override
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

    dbBuilder = new CreateDB(this);
    database = dbBuilder.getReadableDatabase();         
    cursor = database.query(CreateDB.TABLE, null, null, null, null, null, CreateDB.C_CATEGORY + " DESC");
    startManagingCursor(cursor);

    SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, android.R.layout.simple_spinner_item, cursor, FROM, TO);
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

    Spinner spinnerRemote = (Spinner) findViewById(R.id.spinner2);

    spinnerRemote.setAdapter(adapter);
}   

public void createReview(View view)
{
            //createReview runs when a button is clicked
    Spinner spinner = (Spinner)findViewById(R.id.spinner2);

            int index = spinner.getSelectedItemPosition();

    String choice = this.adapter.getItem(index).toString();

    Intent postReview = new Intent(this,Post.class);
    Bundle bundle = new Bundle();
    bundle.putString("CATEGORY", choice);
    postReview.putExtras(bundle);
    startActivity(postReview);
}
  • 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-31T07:24:18+00:00Added an answer on May 31, 2026 at 7:24 am

    Is there a simple way to get the user’s selection (the string value) from a spinner ?

    You don’t have a “string value”.

    You used a SimpleCursorAdapter. Your “value”, therefore, is a Cursor.

    You can call getSelectedItem() on the Spinner, which (for a CursorAdapter-backed Spinner) should return a Cursor positioned on the selected row. From there, read out whatever values you want via getString() and kin.

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

Sidebar

Related Questions

is there a more simple way to get combobox (WinForms) selected items text? string
Is there a simple way to get the names of all the user names
Is there any (simple) way to get some control of the order in which
Is there a simple way to get array of all index paths for the
Is there a simple way in .NET to quickly get the current protocol, host,
I was wondering if there was a simple way to use WMI to get
Is there a simple way to get the parameters at the end of an
Is there a simple way to retrieve a filtered list of files from an
Is there a simple way of getting a HTML textarea and an input type=text
Is there a simple way to cache MySQL queries in PHP or failing that,

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.