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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:28:23+00:00 2026-05-18T10:28:23+00:00

I have two spinners in an activity, A and B. Each spinner uses an

  • 0

I have two spinners in an activity, A and B. Each spinner uses an arrayAdapter linked to one or more string-arrays from an XML file. I need multiple because B’s values are populated depending on what is selected in A.

A reference to some arrays that B uses:

<!-- Used in spinner mCcColor -->
<string-array name="component0_color">
    <item>Chocolate</item>
    <item>Yellow</item>
    <item>Strawberry</item>
</string-array>

<!-- Used in spinner mCcColor -->
<string-array name="component1_color">
    <item>Blueberry</item>
    <item>Chocolate</item>
    <item>Dark Chocolate</item>
</string-array>

Next, I created a custom view class that is basically a canvas that I draw bitmaps (png) to. Spinner A is the bitmap, and spinner B is color. So, in order to determine what to draw in this view, I need to know what the user selected in spinner A and B.

It’s fairly easy to pass the position that was selected in both spinner A and spinner B. Here is an example.

ArrayAdapter<CharSequence> adapter1 = ArrayAdapter.createFromResource(this, R.array.cc_components, android.R.layout.simple_spinner_item);
adapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mCcComponent.setAdapter(adapter1);
mCcComponent.setOnItemSelectedListener(new OnItemSelectedListener() {
    public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
     //Call the method of the custom view that draws to the canvas
     mSelectedComponent = position;
     myCustomView.foo(mSelectedComponent, mSelectedCompColor);
     myCustomView.postInvalidate();
});

The problem I have is tying the index numbers of the spinners I pass into the custom view. I could do a bunch of switch case crap based on the position values I pass in, but this seems unnecessary because each case is just a few static values that correlate to the spinner. Plus then I would be tightly coupling my view class to the caller activity.

It seems like it would be much easier and cleaner to set-up a more complex array in XML and have it contain strings and 3 integer values for each string.

Is there a way I can use a complex array without causing headaches for my spinner, the image, or the colors inside the custom view? Is there a better way to approach this? Can anyone point me to some topics or links or post a few lines of code?

Thanks everyone!

Here is a visual representation of what I’m trying to explain, which seems like a cleaner way to solve this:

<!-- Used in spinner mCcColor -->
<array name="component1_color">
    <item>Blueberry</item>
     <red>81</red>
     <green>27</green>
     <blue>21</blue>
    <item>Chocolate</item>
     <red>45</red>
     <green>21</green>
     <blue>6</blue>
</array>
  • 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-18T10:28:24+00:00Added an answer on May 18, 2026 at 10:28 am

    Why not create a class for each of these, so you don’t deal with the array directly, but go through functions?

    Then you can have listeners if you want, so that the two spinners will be informed when there is a change and can adapt.

    If you are worried about tight coupling, encapsulating the shared array will remove this difficulty.

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

Sidebar

Related Questions

i have two richtextboxes one below the other in my application.when the user start
I have two lists: List<string> _list1; List<string> _list2; I need add all _list2 different
I have two tables in a legacy database... tblParentTable (int id, string specialIdentifier, ...)
Have two tables with a linking table between them. USERS +-------+---------+ | userID| Username|
I have two tables: CREATE TABLE 'sales_sheet' ( `_id` int(11) NOT NULL AUTO_INCREMENT, `_typed_by`
I have two distinct databases as a source for a Silverlight RIA application. They
I have two tables in my database, table1 and table2. They are identical. But
I have two nested repeaters in my *.aspx page. <asp:Repeater runat=server id=rptMain> <ItemTemplate> <h1><%#DataBinder.Eval(Container.DataItem,
I am working with a countdown timer and have it set so that it
I am writing my first simple Android App: It loads temperature samples from a

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.