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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:23:30+00:00 2026-06-12T17:23:30+00:00

I have an Activity with multiple Spinners in it (around 8-9). The code that

  • 0

I have an Activity with multiple Spinners in it (around 8-9). The code that I am using is as follows:

Spinner sp1, sp2, sp3, sp4, sp5;
sp1 = (Spinner) findViewById(R.id.spinner1);
sp2 = (Spinner) findViewById(R.id.spinner2);
sp3 = (Spinner) findViewById(R.id.spinner3);
sp4 = (Spinner) findViewById(R.id.spinner4);
sp5 = (Spinner) findViewById(R.id.spinner5);

sp1.setOnItemSelectedListener(this);
sp2.setOnItemSelectedListener(this);
sp3.setOnItemSelectedListener(this);
sp4.setOnItemSelectedListener(this);
sp5.setOnItemSelectedListener(this);

//Outside onCreate I'm using the following to handle the spinner Item Selected event.

@override
public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
        long arg3) {
    // TODO Auto-generated method stub
    switch (arg0.getId()) {
    case R.id.spinner1:
        Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
        break;
    case R.id.spinner2:
        Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();         
        break;
    case R.id.spinner3:
        Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
        break;
    case R.id.spinner4:
        Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
        break;
    case R.id.spinner5:
        Toast.makeText(getApplicationContext(), arg0.getItemAtPosition(arg2).toString(), Toast.LENGTH_LONG).show();
        break;
    }
}

@Override
public void onNothingSelected(AdapterView<?> arg0) {
    // TODO Auto-generated method stub

}

But the problem is I’m not getting any Toast on selecting the item in any of the spinners. Any help would be appreciated. Thanks in advance.

  • 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-12T17:23:31+00:00Added an answer on June 12, 2026 at 5:23 pm
    package com.meta;
    
    import android.app.Activity;
    import android.os.Bundle;
    import android.view.View;
    import android.widget.AdapterView;
    import android.widget.AdapterView.OnItemSelectedListener;
    import android.widget.Spinner;
    import android.widget.Toast;
    
    import com.meta.R;
    
    public class SpinnerActivity extends Activity{
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
            Spinner sp1, sp2, sp3, sp4, sp5;
            sp1 = (Spinner) findViewById(R.id.spinner1);
            sp2 = (Spinner) findViewById(R.id.spinner2);
            sp3 = (Spinner) findViewById(R.id.spinner3);
            sp4 = (Spinner) findViewById(R.id.spinner4);
            sp5 = (Spinner) findViewById(R.id.spinner5);
    
            sp1.setOnItemSelectedListener(myListener);
            sp2.setOnItemSelectedListener(myListener);
            sp3.setOnItemSelectedListener(myListener);
            sp4.setOnItemSelectedListener(myListener);
            sp5.setOnItemSelectedListener(myListener);
    
    
    
        }
    
        OnItemSelectedListener myListener=new OnItemSelectedListener() {
    
            @Override
            public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
                    long arg3) {
                 switch (arg2) {
                    case 1:
                        Toast.makeText(SpinnerActivity.this,"Spinner 1", Toast.LENGTH_LONG).show();
                        break;
                    case 2:
                        Toast.makeText(SpinnerActivity.this, "Spinner 2", Toast.LENGTH_LONG).show();         
                        break;
                    case 3:
                        Toast.makeText(SpinnerActivity.this, "Spinner 2", Toast.LENGTH_LONG).show();
                        break;
                    case 4:
                        Toast.makeText(SpinnerActivity.this,"Spinner 2", Toast.LENGTH_LONG).show();
                        break;
                    case 5:
                        Toast.makeText(SpinnerActivity.this, "Spinner 2", Toast.LENGTH_LONG).show();
                        break;
                    }
    
            }
    
            @Override
            public void onNothingSelected(AdapterView<?> arg0) {
                // TODO Auto-generated method stub
    
            }
        };
    
    
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table that essentially has: person activity-code activity-value There are multiple activity-codes
I have a website that calculates a users involvement/activity using multiple MySQL queries. For
I have an Activity that hosts multiple fragments using the actionbar's tab functionality. One
I have an Activity A that calls an Activity B using startActivityForResult() . Under
I have two spinners in an activity, A and B. Each spinner uses an
I have an activity that offloads multiple uploads to a Intent Service. Each upload
I have an activity for initialising a game, that does multiple selects and inserts
I currently have multiple activity that needs to perform an asynctask for http post
I have one Activity with multiple Fragments. I am also using actionbarSherlock for my
I have added multiple ovals on map view by using below code but I

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.