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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:23:44+00:00 2026-05-18T08:23:44+00:00

I am working with Spinner, cursors and adapters. I want to setup a click

  • 0

I am working with Spinner, cursors and adapters.

I want to setup a click listener for the spinner so that once a user selects an item from the spinner it gets the current selected item and then carrys out some other tasks ( all this extra code is fine, its just 1 problem I am having)…. It kind of works, however, once I declare the setOnItemSelectedListener callback, since the cursor has already been populated, the event is fired as soon as the app launches.

I guess I need a way to define the cursor without selecting an initial item so that the event doesnt fire (since an item will not be selected). Or is there another better way to achieve this?

Basically, as it stands, once the app loads the setOnItemSelectedListener function is firing because the cursor is being populated ( i think). Moreover, ignoreing the fact that the event is firing too soon, if I then select the -same- item in the spinner, it doesnt fire the event sincethe item didnt change. SHould I be using a different callback instead of setonitemslectedlistener? Here is the code I have so far.

            c = db.getallrecents();
    startManagingCursor(c);

    busnumspinner = (Spinner) findViewById(R.id.Spinner01);

        SimpleCursorAdapter spinneradapter = new SimpleCursorAdapter(this,
                R.layout.lvlayout, c, spincol, spinto);

    busnumspinner.setAdapter(spinneradapter);


    busnumspinner.setOnItemSelectedListener(new OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parentView, View selectedItemView, int position, long id) {
            String spinnerString = null;
            Cursor cc = (Cursor)(busnumspinner.getSelectedItem());
            if (cc != null) {
                spinnerString = cc.getString(
                    cc.getColumnIndex("busnum"));
                text = spinnerString;
            }

            showDialog(DATE_DIALOG_ID);

        }

        @Override
        public void onNothingSelected(AdapterView<?> parentView) {
            // your code here
        }
    });
  • 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-18T08:23:45+00:00Added an answer on May 18, 2026 at 8:23 am

    This has already been discussed in this question. Look there, though it has a similar answer like the one given by blindstuff.

    EDIT:

    If the onItemSelectedListener is not firing when you need it, then you probably need a onClickListener in eachtext item of the droplist and get in there the current position of the selected item of the spinner. The problem is that as it is said here spinner don’t support this event, but maybe you can get it by doing something similar to the explained in this stackoverflow question. I haven’t tried it so I’m not sure it will work.

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

Sidebar

Related Questions

I've got a spinner working where onItemSelected outputs a Toast. I want it to
Alright so i have been working on this Dynamic load of a spinner from
I am working on an Android code that on click of a button inserts
I'm working on a project that parse data from web service and shows in
I'm working with 2 spinner in my app, and I want to do this
my coding is working well .But I want to store the edited spinner value
On opening the activity, the user chooses an option from a spinner. I have
I have a jquery form spinner script that generates text fields based on user
I am working in Android. I want to design a spinner of song categories.
I am working on an android project and I am using a spinner which

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.