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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T02:09:05+00:00 2026-06-09T02:09:05+00:00

I would like to develop an android app with three spinners. These three spinners

  • 0

I would like to develop an android app with three spinners.
These three spinners will contain the information about the cars, which are brands, models, and engines.

  1. So, after the first spinner(brand) is chosen, the contents of the second spinner(model) should be added depend on the selected brand.
  2. Next, the second spinner will be selected and then the third spinner(engine) will be added.

I have searched with keyword "Android Multi Spinners" and "Android listener for spinners" on google and stackoverflow for almost a week, but I still didn’t find the solution.

Here are the links that I got the idea for my code

  • multiple spinner's simple doubts
  • Spinner listener not working

So, I have two versions of my source code, but both of them didn’t work. (Edited: Working now)

For the first version

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Spinner;

public class AddCarActivity extends Activity {

    private Spinner spnBrand, spnModel, spnEngine;

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

        addItemsOnSpnBrand();   
    }

    public void addItemsOnSpnBrand() {
        spnBrand = (Spinner) findViewById(R.id.spnBrand);
        List<String> list = new ArrayList<String>();

        //Get Brand Database and Add to List

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spnBrand.setAdapter(dataAdapter);       

        addListenerOnSpnBrandItemSelection();
    }

    public void addListenerOnSpnBrandItemSelection() {
        spnBrand = (Spinner) findViewById(R.id.spnBrand);       
        spnBrand.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                addItemOnSpnModel(parent.getItemAtPosition(pos).toString());
            }

            public void onNothingSelected(AdapterView<?> parent) {
                return;
            }
        });
    }

    public void addItemOnSpnModel(String inBrand) {
        spnModel = (Spinner) findViewById(R.id.spnModel);
        List<String> list = new ArrayList<String>();

        //Get Model Database and Add to List

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spnSeries.setAdapter(dataAdapter);      

        addListenerOnSpnModelItemSelection();
    }

    public void addListenerOnSpnModelItemSelection() {
        spnModel = (Spinner) findViewById(R.id.spnModel);
        spnModel.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
                addItemOnSpnEngine(parent.getItemAtPosition(pos).toString());               
            }

            public void onNothingSelected(AdapterView<?> parent) {
                return;
            }
        });
    }

    public void addItemOnSpnEngine(String inModel) {
        spnEngine = (Spinner) findViewById(R.id.spnEngine);
        List<String> list = new ArrayList<String>();
    
        //Get Engine Database and Add to List

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spnEngine.setAdapter(dataAdapter);
    }
}

Here is my Second version

public class AddCarActivity extends Activity implements OnItemSelectedListener {

    private Spinner spnBrand, spnModel, spnEngine;

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

        addItemsOnSpnBrand();
    }

    public void onItemSelected(AdapterView<?> parent, View view, int position,long arg3) {
        int id = parent.getId();
        switch (id) 
        {
            case R.id.spnBrand:
                addItemOnSpnModel(parent.getItemAtPosition(position).toString()); break;
            case R.id.spnModel:
                addItemOnSpnEngine(parent.getItemAtPosition(position).toString()); break;
        }
    }

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

    public void addItemsOnSpnBrand() {
        spnBrand = (Spinner) findViewById(R.id.spnBrand);
        List<String> list = new ArrayList<String>();

        //Get Brand Database and Add to List
    
        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spnBrand.setAdapter(dataAdapter);

        spnBrand.setOnItemSelectedListener(this);
    }

    public void addItemOnSpnModel(String inBrand) {
        spnModel = (Spinner) findViewById(R.id.spnModel);
        List<String> list = new ArrayList<String>();

        //Get Model Database and Add to List

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spnModel.setAdapter(dataAdapter);

        spnModel.setOnItemSelectedListener(this);
    }

    public void addItemOnSpnEngine(String inModel) {
        spnEngine = (Spinner) findViewById(R.id.spnEngine);
        List<String> list = new ArrayList<String>();
    
        //Get Engine Database and Add to List

        ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, list);
        dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spnEngine.setAdapter(dataAdapter);
    }
}

Thank you everyone that have tried to help me. I just found the problem when retest the codes for answering Hip Hip Array. I use the wrong variable in addListenerOnSpnModelItemSelection(). I mistaken to use spnBrand instead of spnModel. Now, these two versions are worked, so I corrected them and hope that they will help the others that try to use the multi-spinners in android.

  • 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-09T02:09:08+00:00Added an answer on June 9, 2026 at 2:09 am

    Lets say,you have 3 spinners spinner_1,spinner_2 and spinner_3 then:

    spinner_1.setOnItemSelectedListener(new OnItemSelectedListener() {
    
                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int position, long arg3) {
    
                                if(spinner_1.getSelectedItem().equals("Spin1-Item-1")){
                                {
                                      // set adapter to spinner_2 here for "Spin1-Item-1" selected
                                }
                                else if(spinner_1.getSelectedItem().equals("Spin1-Item-2"))
                                {
                                     // set adapter to spinner_2 for "Spin1-Item-2" not selected
                                }
                                else 
                                {
                                     // set adapter to spinner_2 for "Spin1-Item-3" not selected
                                }
                }    
                @Override
                public void onNothingSelected(AdapterView<?> arg0) {                
                }
    });
    spinner_2.setOnItemSelectedListener(new OnItemSelectedListener() {
    
                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int position, long arg3) {
    
                                if(spinner_2.getSelectedItem().equals("Spin2-Item-1")){
                                {
                                      // set adapter to spinner_3 here for "Spin2-Item-1" selected
                                }
                                else if(spinner_2.getSelectedItem().equals("Spin2-Item-2"))
                                {
                                     // set adapter to spinner_3 for "Spin2-Item-2" not selected
                                }
                                else 
                                {
                                     // set adapter to spinner_3 for "Spin2-Item-3" not selected
                                }
                }    
                @Override
                public void onNothingSelected(AdapterView<?> arg0) {                
                }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to develop an Android application which will have a local database.
Hi there I'm starting to develop an Android app which will be using a
I'm using phonegap to develop an android app and I would like to fix
I would like to develop an Android app to access our web site. How
I would like to develop an android application with the following description: The app
I would like to develop an android/iphone app for automatic check-in/check-out based on the
I would like to develop a game on Android platform, I have about a
I developed a paid app for Android and would like to develop a demo
I would like to develop a selection-tool for Screen which ignores the leading spaces
I would like to develop a MS paint like app for the iPhone. Could

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.