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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:29:55+00:00 2026-06-09T14:29:55+00:00

I am new to Android Development so the query may seem novice. I was

  • 0

I am new to Android Development so the query may seem novice.

I was trying to make an app where there are a couple of spinners and after the user selects one spinner the other spinner gets filled up with the data based on the selection in spinner1.

ie. First user selects Country. Based on country the spinner 2 gets filled up with states and based on the state the spinner 3 gets filled up with cities.

I have created all the countries as a string arrays in strings.xml like –

<string-array name="Country">
    <item >USA</item> etc...

Similarly states have been created in the string.xml as – (Each Country is a separate entry with a naming convention as (country name)_(States)

<string-array name="USA_state">
    <item >New York</item> etc...

Now I want the second spinner to populate based in country selection. Hence the formula used by me is to the get the second spinner is –

String getstate = country[index]+"_"+"state";
state=getResources()
.getStringArray(getResources().
getIdentifier(getstate,null,getPackageName()));

When I run this app the Manactivity just shows a blank screen and I donot get any Debug info and get an error “the jar file android.jar has no source attached”.

Please help. The complete mainActivity is given below –

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

public class MainActivity extends Activity {
String[] country;
String[] state;


@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    country = getResources().getStringArray(R.array.country); 
    Spinner country_spinner =(Spinner) findViewById(R.id.country); 
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, country);
    country_spinner.setAdapter(adapter); 
    country_spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
        public void onItemSelected (AdapterView<?> arg0, View arg1, int arg2, long arg3){
            int index = arg0.getSelectedItemPosition();
            Toast.makeText(getBaseContext(), "You have Selected"+country[index]+"country", Toast.LENGTH_SHORT).show();
            Fill (index);
        }
        public void onNothingSelected(AdapterView<?> arg0) {}
    });


}

protected void Fill(int index) {
    // TODO Auto-generated method stub
    //Field resField=R.array.getField(country[index]);
    //int getstate = resField.getInt(null);
    String getstate = country[index]+"_"+"state";
    state=getResources().getStringArray(getResources().getIdentifier(getstate,null,getPackageName()));
    Spinner state_spinner = (Spinner) findViewById(R.id.state);
    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, state);
    state_spinner.setAdapter(adapter);
    state_spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
        public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2, long arg3){
            int index2 = arg0.getSelectedItemPosition();
            Toast.makeText(getBaseContext(),"You Have Selected "+state[index2] + " statet",Toast.LENGTH_SHORT).show();
        }
        public void onNothingSelected(AdapterView<?> arg0){}
    });

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_main, menu);
    return true;
}
  • 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-09T14:29:56+00:00Added an answer on June 9, 2026 at 2:29 pm

    I was able to solve the problem. The final code is given below. This is a nested approach so if there are 3 spinners (like city after state) do we again nest the code for that spinner? Is there any simpler method?

    ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, country);
        country_spinner.setAdapter(adapter); 
        country_spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    
            public void onItemSelected (AdapterView<?> arg0, View arg1, int arg2, long arg3){
                int index = arg0.getSelectedItemPosition();
                Toast.makeText(getBaseContext(), "You have Selected"+country[index]+" County", Toast.LENGTH_SHORT).show();
    
                final CharSequence[] state_array = state.getTextArray(index);
                final Spinner state_spinner =(Spinner) findViewById(R.id.state); 
                ArrayAdapter<CharSequence> adapter1 = new ArrayAdapter<CharSequence>(MainActivity.this, android.R.layout.simple_spinner_item, state_array);
                state_spinner.setAdapter(adapter1); 
                state_spinner.setOnItemSelectedListener(new OnItemSelectedListener(){
    
                    public void onItemSelected (AdapterView<?> arg0, View arg1, int arg2, long arg3){
                        final int index = arg0.getSelectedItemPosition();
                        Toast.makeText(getBaseContext(), "You have Selected"+state_array[index]+" State", Toast.LENGTH_SHORT).show();
    
            });
    
                    }
                    public void onNothingSelected(AdapterView<?> arg0) {
                        state_spinner.setAdapter(null);
                    }
                });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to android development and I'm trying to make an android app that
I am new to Android development and am trying to determine if there is
I'm kinda new to android development, but i'm trying to make a xml parser.
I'm new to android development, and im trying to create an app that is
New to both Android development and Java, trying to separate my queries into query
I am new to android development . I'm trying to download and run the
I'm new to Android development. My OS is WinXP. I'm trying to install two
I'm new to Android development and am having an issue with my first app's
I am new to android development. I am developing a phonebook app. What I
I am very new to Android development. I am converting my iPhone app to

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.