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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T21:22:26+00:00 2026-05-20T21:22:26+00:00

I want to have three Spinners with contents which depend on each other. E.g.

  • 0

I want to have three Spinners with contents which depend on each other.

E.g. Spinner1 displays {item1, item2} and Spinner2 either {item3, item4} or {item5, item6} depending on whether item1 or item2 is selected on Spinner1.
The same I want for Spinner 3, which reacts to changes of Spinner1 and/or Spinner2.

For the latter, I have to determine first which of the possible value sets is shown atm in Spinner2.

My question is kind of similar to this question, but I don’t know what to do after getting the adapter.

That’s what I have so far:

ArrayAdapter adapter1 = (ArrayAdapter) spinner2.getAdapter();
if(items_spinner1[0].contentEquals(adapter1.getItem(0)))
{
    //...
}

I get the adapter, ask for the first value and compare it to the first String value of my Array to identify it. It doesn’t at all seem elegant to me. Is there an easier solution?

  • 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-20T21:22:26+00:00Added an answer on May 20, 2026 at 9:22 pm

    You say the contents of the later spinners depend on the selection in the earlier ones, but the code you posted depends only on the contents of a spinner.

    adapter1.getItem(0) returns the first item in the list, not the currently selected item. To get the currently selected item, use the spinner’s (not the adapter’s) getSelectedItem() method.

    You could, for example, put something like this in your first Spinner’s onItemSelectedListener (edited based on your comment below):

    public void onItemSelected (AdapterView<?> parent, View view, int position, long id) {
        Object selectedItem = parent.getSelectedItem();
    
        // Do this if the first Spinner has a set of options that are
        // known in advance.
        if (/*selectedItem is something*/) {
            // Set up the second Spinner in some way
        } else if (/*selectedItem is something else*/) {
            // Set up the second Spinner in another way
        }
    
        // OR, if you need to do something more complex
        // that would cause too much clutter here, do this.
        fillSecondSpinner(selectedItem);
    }
    

    Then place something similar in the second Spinner’s onItemSelectedListener. Get the selected items from the first and second Spinners using getSelectedItem() (or the item positions using getSelectedItemId() for the first and the position parameter for the second). Use the selected items to set up the third.

    Edit: The OnItemSelectedListener for the second Spinner would look something like this.

    // This must be defined in the enclosing scope.
    final Spinner firstSpinner;  // Must be final to be accessible from inner class.
    Spinner secondSpinner;
    // ...
    secondSpinner.setOnItemSelectedListener(new OnItemSelectedListener {
        public void onItemSelected (AdapterView<?> parent, View view, int position, long id) {
            // Again, usually the selected items should be of
            // a more specific type than Object.
            Object firstSelection = firstSpinner.getSelectedItem();
            Object secondSelection = parent.getSelectedItem();
    
            fillThirdSpinner(firstSelection, secondSelection);
        }
    
    public void onNothingSelected (AdapterView<?> parent) { }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two spinners. When an item is selected from spinner1, I want spinner2's
a have three column layout and i want to have three divs inside the
I have three HTML objects and want to arrange Previous button at the left
I have three images that I want to cycle through when clicking on a
I have three lists that I want to convert into one list. When I
I have three problems: I want to create resizable shapes with box bounding... I
I have three UILabel with different font and I want to put then on
Hi I have three tables and I want to know how much jobs with
I have three tables (individuals, groups & recordlabels) and want use the information between
I have three source files in a folder. I simply want to compile them

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.