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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T22:58:13+00:00 2026-06-10T22:58:13+00:00

I am working on an application for Android. For this I am making an

  • 0

I am working on an application for Android. For this I am making an Activity in which you select your country and then a spot in that country. I have one spinner that contains a list of all available countries. Now, what I want it to do is get the country that has been selected, then filter a list of spots that I have for the items that start with the country that has been selected. Then it should put the spots for the selected country into a different spinner. Just for clarity, the list of countries is just a list of countries, and the list of spots looks like:

  • Country1 – Spot1

  • Country1 – Spot2

  • Country2 – Spot1

  • Country2 – Spot2

And so on.

This is what I thought the code should work like:

  • Get selected country from spinner 1.
  • Make a new ArrayList containing the spots.
  • Make a second empty ArrayList.
  • For each entry of the ArrayList containing the spots, check if it starts with the selected country.
  • If so, add it to the second ArrayList.
  • Once this is all done, make an ArrayAdapter with the second ArrayList.
  • Set this ArrayAdapter for spinner 2.

I tried to achieve this with the following code:

public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
    String selectedCountry = parent.getItemAtPosition(pos).toString();
    ArrayList<CharSequence> arraylist = new ArrayList<CharSequence>();
    arraylist.addAll(R.array.spots_array);
    ArrayList<CharSequence> arraylist2 = new ArrayList<CharSequence>();
    for (i=0; i<arraylist.size(); i++) {
        String delimiter = " - ";
        if ((arraylist(i).split(delimiter)).equals(selectedCountry)) {
            arraylist2.add(arraylist(i).string.substring(string.lastIndexOf('-') + 1));
        }

    }
    ArrayAdapter<CharSequence> arrayAdapter2 = ArrayAdapter.createFromResource(this,  arraylist2<CharSequence>, android.R.layout.simple_spinner_item);
    arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spinner2.setAdapter(arrayAdapter2);
    spinner2.setOnItemSelectedListener(this);
}

But it gives several errors:

  • At addAll() it says: “The method addAll(int, Collection) in the type ArrayList is not applicable for the arguments (int)”
  • At arraylist it says: “The method arraylist(int) is undefined for the type Configuration”
  • At string (inside substring) it says: “string cannot be resolved”

I am still relatively new to Android, and am having a lot of trouble getting this working. Can anybody please help me out?

  • 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-10T22:58:14+00:00Added an answer on June 10, 2026 at 10:58 pm

    There is a lot of little mistakes in your code :

    • To access an element in an arraylist use the get(position) method
    • When you add your “spot_array”, you actually add the id of the resource, not the array itself (see here)

    Here is your code updated, it should works or may need some tweaks

    public void onItemSelected(AdapterView<?> parent, View view, int pos, long id) {
            String selectedCountry = parent.getItemAtPosition(pos).toString();
            List<CharSequence> arraylist = new ArrayList<CharSequence>();
            arraylist.addAll(Arrays.asList(getResources().getTextArray(R.array.spots_array)));
            List<CharSequence> arraylist2 = new ArrayList<CharSequence>();
            String delimiter = " - ";
            for (int i=0; i<arraylist.size(); i++) {
                String country = arraylist.get(i).toString();
                if (country.contains(selectedCountry)) {
                    arraylist2.add(country.substring(country.lastIndexOf('-') + 2));
                }
    
            }
            ArrayAdapter<CharSequence> arrayAdapter2 = ArrayAdapter.createFromResource(this,  android.R.id.text1, android.R.layout.simple_spinner_item);
            arrayAdapter2.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
            spinner2.setAdapter(arrayAdapter2);
            spinner2.setOnItemSelectedListener(this);
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am making an android application in which I have put 10 images and
I am making an application that has Activity which communicates with a single service,
This is making me a bit crazy. I have the following Application: Activity A
I'm working on a multiplatform application for windowsphone, iphone and android. I do this
Hello Android programmers, I am working on parsing a website in my application. This
My Android application was working in English and I have to provide the users
I am working on Android Application. Now I have requirement of search the entered
I am working on an application for android and we since we have lots
I have an android application and web-server working together. Now I want user log
I am working on an android application which is sort of an e-reader but

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.