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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T03:25:59+00:00 2026-06-18T03:25:59+00:00

I am building a cab booking app. This app needs to provide a feature

  • 0

I am building a cab booking app. This app needs to provide a feature to the cab driver to specify which city he will operate from. To enhance the experience, I need to provide a Select State drop down and then a Select City dropdown.

The states are listed in a string-array like this.

<string-array name="stateArray">
    <item>Andaman and Nicobar Islands</item>
    <item>Andhra Pradesh</item>
    <item>Arunachal Pradesh</item>
    <item>Assam</item>
</string-array>

The city’s are listed in a string-array like this.

<string-array name="AndhraPradesh">
    <item>Adilabad</item>
    <item>Adoni</item>
    <item>Amadalavalasa</item>
    <item>Amalapuram</item>
</string-array>

In the listeners I have

Setting the states is really easy in the layout xml file android:entries="@array/stateArray".

I have seen many other stackoverflow questions recommending the ArrayList and setAdapter. I am wondering if there is a relatively easy way to set the entries for the city too, programmatically depending on the state selected.

  • 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-18T03:26:00+00:00Added an answer on June 18, 2026 at 3:26 am

    Use OnItemSelectedListener.
    I assume you have two Spinners. It will be something like this.

    spinner1.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
        @Override
        onItemSelected(AdapterView<?> parent, View view, int position, long id) {
            YourAdapter adapter = (YourAdapter) spinner2.getAdapter();
    
            switch (position) {
                case COUNTRY_ONE:
                    adapter.setData(resources.getArray(R.array.cities_you_need_1));
                    break;
    
                case COUNTRY_TWO:
                    adapter.setData(resources.getArray(R.array.cities_you_need_2));
                    break;
            }
        }
    
        @Override
        onNothingSelected(AdapterView<?> parent) {
            ((YourAdapter) spinner2.getAdapter()).clear();
        }
    });
    

    Note that methods clear() and setData() are custom helper methods. There are no such methods in SpinnerAdapter.
    Or you can implement objects and compare id’s instead if indexes. The code above is not tested and is just to show an idea.

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

Sidebar

Related Questions

Building our Android app from Ant fails with this error: [apply] [apply] UNEXPECTED TOP-LEVEL
Building an app that gets a list of widgets from an SQlite database then
Building an iOS app that needs to display some HTML string in a UIWebView
building upon the $.fn.serializeObject() function from this question , i'd like to be able
Building an app with the Facebook JavaScript API that will embedded into a page
Building a simple asp.net web app just to test things out (will obviously refactor
building a site using PHP and MySQL that needs to store a lot of
Building a Django app on a VPS. I am not very experienced with setting
Building an iPhone OS application that will allow users to anonymously post information to
Building on this answer: https://stackoverflow.com/a/2349824/1382306 Are there further guidelines in A and B's usages,

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.