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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T21:13:06+00:00 2026-05-31T21:13:06+00:00

I have a button and a spinner (originally hidden). When user presses a button,

  • 0

I have a button and a spinner (originally hidden). When user presses a button, spinner gets populated with items and becomes visible. Now I would like to add OnItemSelectedListener to the spinner. and I have tried many tutorials with no luck.

This is my OnCreate function

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

    Button load_routes = (Button)findViewById(R.id.load_routes);
    Spinner routes = (Spinner)findViewById(R.id.routes_list);

    load_routes.setOnClickListener(new View.OnClickListener()
    {
        public void onClick(View v)
        {
            load_routes(v);
        }
    });

    routes.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener()
    {
        public void onItemSelected(AdapterView<?> arg0, View v, int position, long id)
        {
            Log.v("routes", "route selected");
        }

        public void onNothingSelected(AdapterView<?> arg0)
        {
            Log.v("routes", "nothing selected");
        }
    });
}

This is my load_routes function

private void load_routes(View v)
{
    Spinner routes = (Spinner)findViewById(R.id.routes_list);
    List<String> routes_list = RouteParser.get_routes();
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, routes_list);
    routes.setAdapter(adapter);

    TableRow list_of_routes_row = (TableRow)findViewById(R.id.list_of_routes_row);
    list_of_routes_row.setVisibility(View.VISIBLE);
}

This set up does not work. The only way I got this to work is when I setup my listener as routes.setOnItemSelectedListener(this) Then I implement OnItemSelectedListener and include the functions neccessary. But I have multiple spinners and need to create separate listeners for different spinner. Any help will be appreciated. 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-05-31T21:13:08+00:00Added an answer on May 31, 2026 at 9:13 pm

    Declare your Spinner as field instantiate the listener once you do findViewById and use it wherever you want.

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

Sidebar

Related Questions

I have a button that I would like to disable when the form submits
I have a button that says Sort and when a user normal/short presses the
In main.xml I would like to have a spinner1 with two radio buttons and
I have a button with class MyButton defined somewhat like this: .MyButton{ color:black; background:white;}
I have a spinner, which mostly works. If a user selects one of the
I have one spinner, one button and a ListView. I want to choose item
I have a spinner and when the user selects I want to call another
I have created a Spinner and have populated it with values for my app
I'm using Spinner,EditText and Button in one page.The spinner has these items ... Following:
I have implemented button which clicks and opens dialog with spinner inside as described

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.