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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T22:22:47+00:00 2026-06-02T22:22:47+00:00

First, yes I’ve browsed through a number of possible solutions and they’ve gotten me

  • 0

First, yes I’ve browsed through a number of possible solutions and they’ve gotten me close but I’m missing some small crucial step that I just can not find for the life of me. Everything loads fine. The first spinner (Category) is populated as it should be, I can tell that the second spinner (Color) is getting populated through the create method but I’ve missed where to tell it to recreate itself when the user selects a Category. Here’s all my code as it stands now.

package yarn.pack.name;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Adapter;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.SpinnerAdapter;
import android.widget.AdapterView.OnItemSelectedListener;

public class YarnDatabaseActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    try {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        Spinner Category_Add_Spinner = Create_Category_Add_Spinner();
        Spinner Color_Add_Spinner = Create_Color_Add_Spinner(null);
    } catch (Exception e) {
        Log.e("ERROR", e.toString());
        e.printStackTrace();
    }
}

// Creates the Category Spinner for the Add section sends the choice made to
// a method for populating the color spinner
public Spinner Create_Category_Add_Spinner() {
    Spinner Category_Add_Spinner = (Spinner) findViewById(R.id.categoryAddID);
    String[] Category_Add_Spinner_Array = getResources().getStringArray(
            R.array.categoryNames);
    SpinnerAdapter Category_Add_Spinner_Adapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_dropdown_item,
            Category_Add_Spinner_Array);
    Category_Add_Spinner.setAdapter(Category_Add_Spinner_Adapter);
    Category_Add_Spinner
            .setOnItemSelectedListener(new Category_Add_Spinner_Listener());
    return Category_Add_Spinner;
}

// The listener for the Category Spinner that sends whatever choice made to
// the method that populates the second spinner.
public class Category_Add_Spinner_Listener implements
        OnItemSelectedListener {

    public void onItemSelected(AdapterView<?> Category_Add_Adapter_View,
            View v, int position, long row) {
        String Category_Add_Choice = Category_Add_Adapter_View
                .getItemAtPosition(position).toString();
        Create_Color_Add_Spinner(Category_Add_Choice);
    }

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

    }

}

// Creates the Color Spinner for the Add section
public Spinner Create_Color_Add_Spinner(String category_Add_Choice) {
    String[] Color_Add_Spinner_Array = null;
    Spinner Color_Add_Spinner = (Spinner) findViewById(R.id.colorAddID);
    if (category_Add_Choice == "Red") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.RedColors);
    } else if (category_Add_Choice == "Pink") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.PinkColors);
    } else if (category_Add_Choice == "Orange") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.OrangeColors);
    } else if (category_Add_Choice == "Yellow") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.YellowColors);
    } else if (category_Add_Choice == "Green") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.GreenColors);
    } else if (category_Add_Choice == "Blue") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.BlueColors);
    } else if (category_Add_Choice == "Purple") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.PurpleColors);
    } else if (category_Add_Choice == "Neutral") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.NeutralColors);
    } else if (category_Add_Choice == "Mix") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.MixColors);
    } else if (category_Add_Choice == "Fleck") {
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.FleckColors);
    } else
        Color_Add_Spinner_Array = getResources().getStringArray(
                R.array.MixColors);     
    SpinnerAdapter Color_Add_Spinner_Adapter = new ArrayAdapter<String>(
            this, android.R.layout.simple_spinner_dropdown_item,
            Color_Add_Spinner_Array);
    Color_Add_Spinner.setAdapter(Color_Add_Spinner_Adapter);
    Color_Add_Spinner
            .setOnItemSelectedListener(new Color_Add_Spinner_Listener());
    return Color_Add_Spinner;
}
}

I’m pretty well certain that whatever I’m missing is something stupidly obvious but I’ve been working on this for so long and my time is short that I thought I’d reach out here and see if I couldn’t get some light shining on the subject. Thanks in advance for any help you all can give me.


Sorry about the naming conventions. I generally name so it makes the most sense to myself. Anyway, it turns out that the issue was my using == instead of .equals
Made that change and it worked without a hitch! Thank you everyone for your help.

  • 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-02T22:22:48+00:00Added an answer on June 2, 2026 at 10:22 pm

    Your code is almost working, not really perfect, but it could work quickly :

    1. never use == to compare strings in java. Always use stringA.equals( stringB ). I guess this is your only problem.
    2. respect java naming conventions, it would be easier to read.

    As pointed out by @Frankenstein, making your widget data members is often more clear and efficient than always re-getting them from the layout using findViewById.

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

Sidebar

Related Questions

First, yes i know this is a big security NONO . But the scenario
FIRST: Yes, I know about CONCATENATE and CONTINUEIF, but I might not be smart
First, yes it's HW - really tried but not sure of something so ill
First of all, yes, I'm aware of this question , but the answer doesn't
At first - yes, I've tried to find my problem here, but can't make
Yes, I know that less was in first place written for node.js. But I
If yes, the first query below should be correct, but shows error ORA-00979: not
First of -yes this IS a homework- but it's primarily a theoretical question rather
First of all yes I posted this on another board but I gave them
First, yes I know about this question , but I'm looking for a bit

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.