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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T09:27:22+00:00 2026-06-09T09:27:22+00:00

I’m pretty new to this, and I have a question that is probably pretty

  • 0

I’m pretty new to this, and I have a question that is probably pretty simple.

I have 3 spinners, and I want to populate each spinner from an array based on the choice the user made on the previous spinners.

Right now i have it set up to display a toast with the selected data, but I want to set up an activity to open up, but that’s later. Right now I need to know how to populate the spinner from an array from the strings.xml.

.Java

import java.util.ArrayList;
import java.util.List;

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

/**
 * @author madonk
 *
 */
public class Region extends Activity {

Spinner sp1,sp2,sp3;
ArrayAdapter<String> reg_adp,sw_city_adp,sw_lake_charles_adp;
List<String> regions,sw_cities,sw_lake_charles;
int pos;
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_region);

    regions=new ArrayList<String>();

    regions.add("Select a Region");
    regions.add("Southwest");

    sp1= (Spinner) findViewById(R.id.regions_spinner);
    sp2= (Spinner) findViewById(R.id.sw_city_spinner);
    sp3= (Spinner) findViewById(R.id.sw_lake_charles_spinner);

    reg_adp=new ArrayAdapter<String> (this,android.R.layout.simple_dropdown_item_1line,regions);
    reg_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
    sp1.setAdapter(reg_adp);

    sp1.setOnItemSelectedListener(new OnItemSelectedListener() {

        public void onItemSelected(AdapterView<?> arg0, View arg1,
                int arg2, long arg3) {
            // TODO Auto-generated method stub
            pos=arg2;
            add();

        }

        private void add() {
            // TODO Auto-generated method stub
            Toast.makeText(getBaseContext(), ""+pos, Toast.LENGTH_SHORT).show();

            switch(pos)
            {
            case 0:
                sw_cities= new ArrayList<String>();                    
                sw_cities.add("Select a City");


                sw_city_adp=new ArrayAdapter<String>(Region.this,
                        android.R.layout.simple_dropdown_item_1line,sw_cities);
                sw_city_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                sp2.setAdapter(sw_city_adp);

                select();

                break;
            case 1:
                sw_cities= new ArrayList<String>(); 
                sw_cities.add("Select a City");
                sw_cities.add("Lake Charles");
                sw_cities.add("Iowa");
                sw_cities.add("Lake Arthur");

                sw_city_adp=new ArrayAdapter<String>(Region.this,
                        android.R.layout.simple_dropdown_item_1line,sw_cities);
                sw_city_adp.setDropDownViewResource(android.R.layout.simple_dropdown_item_1line);
                sp2.setAdapter(sw_city_adp);

                select();

                break;
            }

        }

        private void select() {
            // TODO Auto-generated method stub

            sp2.setOnItemSelectedListener(new OnItemSelectedListener() {

                public void onItemSelectedregions(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub

                }

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

                }

                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub

                }

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

                }
            });

        }

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

        }

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

        }
    });
    }

stings.xml

<resources>

    <string name="app_name">Louisiana Festivals</string>
    <string name="menu_settings">Settings</string>
    <string name="title_activity_region">Select a Region</string>
    <string-array name="regions_array">
        <item >Southwest</item>
    </string-array>
        <string name="select_a_region">Select a Region</string>
    <string-array name="southwest_cities">
        <item >Lake Charles</item>
        <item >Iowa</item>
    </string-array>
    <string name="sw_select_a_city">Select a City</string>
    <string-array name="lake_charles">
        <item>Contraband days Pirate Festival</item>
        <item>Other festival to be determined</item>
    </string-array>

</resources>
  • 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-09T09:27:24+00:00Added an answer on June 9, 2026 at 9:27 am

    You can get a string array from strings.xml using getStringArray(). So the code snippet you want is:

    String[] regionsArray = getResources().getStringArray(R.array.regions_array);
    regions = new ArrayList<String>(Arrays.asList(regionsArray));
    

    Now whatever you enter into regions_array will end up in the regions ArrayList.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
This could be a duplicate question, but I have no idea what search terms
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported

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.