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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T21:34:59+00:00 2026-06-09T21:34:59+00:00

This must be a simple problem that i might again overlooked. Here is my

  • 0

This must be a simple problem that i might again overlooked. Here is my problem
I have a string array on my string.xml

<string-array name="country_array">
    <item>Alabama</item>
    <item>Florida</item>
    <item>Los Angeles</item>
    <item>Virginia</item>
    <item>California</item>
    <item>Texas</item>
    <item>Hawaii</item>
    <item>Miami</item>
    <item>New Jersey</item>
    <item>Boston</item>
    <item>Philadelphia</item>
    <item>VaChina</item>
 </string-array>

So now I am calling in on my main activity and placed it on my spinner

selectedCountry = (EditText) findViewById(R.id.etCity);
    //get the spinner from resource
    Spinner spinner = (Spinner) findViewById(R.id.spinnerCountry);

    //then defining ArrayAdapter using country_array
    ArrayAdapter<CharSequence> adapter =ArrayAdapter.createFromResource(this, R.array.country_array,
            android.R.layout.simple_spinner_item);
    //set the appearance of widget items that show when open the widget
    adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    //set the adapter to spinner
    spinner.setAdapter(adapter);
    //set the action listener
    spinner.setOnItemSelectedListener(listener);

Now on my onclicklistener of my spinner this is my code

View.OnClickListener selectCountry = new View.OnClickListener() {
         public void onClick(View v) {
             Spinner spinner = (Spinner) findViewById(R.id.spinnerCountry);
             spinner.performClick();
         }  
    };

    private OnItemSelectedListener listener =new OnItemSelectedListener() {
        //do what ever you want to do when item selected
        public void onItemSelected(AdapterView<?> parent, View view, int pos,
                long id) {
            //i get the item using selected item position and set it into selectedCountry
            selectedCountry.setText(parent.getItemAtPosition(pos).toString());          
        }

        public void onNothingSelected(AdapterView<?> parent) {

        }

    };

Every thing works fine until I figured out that on my selectedCountry text is the first item on my array.
Is there anyway that I could add a default value on my edittext?

  • 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-09T21:35:00+00:00Added an answer on June 9, 2026 at 9:35 pm

    Please add “Select Country” in your String array as first item.

    Like

    <string-array name="country_array">
        <item>Select Country</item>
        <item>Alabama</item>
        <item>Florida</item>
        <item>Los Angeles</item>
        <item>Virginia</item>
        <item>California</item>
        <item>Texas</item>
        <item>Hawaii</item>
        <item>Miami</item>
        <item>New Jersey</item>
        <item>Boston</item>
        <item>Philadelphia</item>
        <item>VaChina</item>
     </string-array>
    

    then

    add below code in onItemSelected()

    public void onItemSelected(AdapterView<?> adapterView, View view,int position, long arg3) 
    {
        if(!spinner.getSelectedItem().toString().equalsIgnoreCase("Select Country"))
        {
              selectedCountry.setText(spinner.getSelectedItem().toString());  
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This might be extremely simple: I have a controller that returns a user object
this must be such a simple problem but can someone tell me why this
Been struggling with this simple selector problem a couple of hours now and must
There must be a simple solution to this problem but for the love of
This must be simple, but I can't seem to figure it out. I am
This must be very simple. But I just can't seem to find the proper
This must be so simple, but I can't find it: How do you restore
This must be very simple, but I couldn't find it on the documentation. In
This must be quite simple but I can't seem to figure this out. I've
This is a very simple issue. I must just be doing something stupid: This

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.