Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

169
Views
Sets spinner adapter using for method instead of if-else method

I need to set one spinner adapter dependent on another spinner selection.

For example:

I have 2 spinners. Call it spinner1 and spinner2.

The content of the spinner1 is "fruit, vegetables".

If spinner1 is set to "fruit", spinner2 set to "apple, mango, banana"

If spinner1 is set to "vegetable", spinner2 set to "carrot, cabbage, eggplant"

I already got the solution with the if-else method. But since my real code requires lots of lists on spinner1, it takes lots of if-else methods too to set spinner2.

Does anyone know how to use the "for" method to solve this?

Below is my current code

    spinner1.setAdapter(adapterC);

    spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            String spinner1Selection = spinner1.getSelectedItem().toString();
            if (spinner1Selection("fruit")){
                spinner2.setAdapter(fruitAdapter);
            }
            if (spinner1Selection.equals("vegetable")){
                spinner2.setAdapter(vegetableAdapter);
            }
        }

        @Override
        public void onNothingSelected(AdapterView<?> parent) {

        }
    });
about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!