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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T20:39:46+00:00 2026-05-18T20:39:46+00:00

Hello I have question about android spinner I have spinner which is populated by

  • 0

Hello I have question about android spinner

I have spinner which is populated by array.The array is Country name and Country phone code on every row

Part of the array

<item>355  Albania</item>
<item>213  Algeria</item>
<item>376  Andorra</item>
<item>244  Angola</item>
<item>1264  Anguilla</item>
<item>1268  Antigua and Barbuda</item>
<item>54  Argentina</item>

This is my java code for populating the spinner

final Spinner spnCountry = (Spinner) findViewById(R.id.countries);
ArrayAdapter<CharSequence> adpCountry = ArrayAdapter.createFromResource(
        this, R.array.countries, android.R.layout.simple_spinner_item);
adpCountry
    .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spnCountry.setAdapter(adpCountry);

I want to show only country code on the box and when the spinner is opened to show country name and code on every row.

Can someone help me how to do that?

  • 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-05-18T20:39:47+00:00Added an answer on May 18, 2026 at 8:39 pm

    Loading the Spinner;

    String[] countries = getResources().getStringArray(R.array.countries);
    
    ArrayAdapter<String> adpCountry = new ArrayAdapter<String>();
    for(String country : countries)
    {
        String parts = country.split(" ");
        String code = parts[0];
    
        adpCountry.addItem(code);
    }
    
    adpCountry.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
    spnCountry.setAdapter(adpCountry);
    

    Selecting an item;

    spnCountry.setOnItemSelectedListener(new OnItemSelectedListener()
    {
        @Override
        public void onItemSelected(AdapterView<?> arg0, View arg1, int index, long arg3)
        {
            String country = "";
            String[] countries = getResources().getStringArray(R.array.countries);
    
            String selected = countries[index];
            String[] parts = selected.split(" ");
            for(String part : parts)
            {
                country += part;
            }
    
            TextView txtName = findViewById(R.id.country_name);
            txtName.setText(country);
        }
    
        @Override
        public void onNothingSelected(AdapterView<?> arg0){ /* Unused */ }
    });
    

    (out of heart)

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

Sidebar

Related Questions

Hello I have question about android spinner I have spinner which is populated by
I have a question about type casting. I have the following JSON String: {server:clients,method:whoIs,arguments:[hello]}
I have a question about the source-code binary on Windows. #include <stdio.h> int main()
Hello fellow drupalers, I have a question about ajax loaded views. Lets say i
Hello all,I'm a junior on html,I have a question about css position : first
Hello I have the following error by git-fsck, which cannot be cleaned by git-gc
Today I have question about Eclipse . I use this IDE very long and
I have a question about a regex. Given this part of a regex: (.[^\\.]+)
I have a question about MIMEParsingException. I use Java EE 6 with NetBeans 6.8.
I have a question about Elisp vectors. Are integers and characters actually stored (efficiently)

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.