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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:28:25+00:00 2026-05-28T04:28:25+00:00

I wrote a code for Spinner to bind array of USA States with Spinner

  • 0

I wrote a code for Spinner to bind array of USA States with Spinner in Android. But the problem is it shows reference type data in Spinner item, see the pic

I add android.R.layout.simple_spinner_dropdown_item but not know that what to add in layout. I checked many exemples on google and they add simple_spinner_dropdown_item but i could not find that what to add in layout. below is output and code. I want to show states in list instead of this junky data.

enter image description here

    Spinner spStates = new Spinner(this);
        spStates.setLayoutParams(new LayoutParams(screenWidth, LayoutParams.WRAP_CONTENT));

        final USAStates states[] = new USAStates[51];

        states[0] = new USAStates("Alabama", "AL");
        states[1] = new USAStates("Alaska", "AK");
        states[2] = new USAStates("Arizona", "AZ");
ArrayAdapter<USAStates> adapter = new ArrayAdapter<USAStates>(this, android.R.layout.simple_spinner_item, states);

        adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
        spStates.setAdapter(adapter);
        spStates.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
                USAStates d = states[position];
                Toast.makeText(getApplicationContext(), d.getStateAbrivation(), Toast.LENGTH_LONG).show();

            }

            public void onNothingSelected(AdapterView<?> parent) {
            }
        });




public class USAStates {
        private String _Statename;
        private String _StateAbrivation;

        public USAStates(String pStatename, String pStateAbrivation) {
            Statename(pStatename);
            StateAbrivation(pStateAbrivation);
        }
        public void Statename(String pStatename) {
            _Statename = pStatename;
        }
        public void StateAbrivation(String pStateAbrivation) {
            _StateAbrivation = pStateAbrivation;
        }

        public String getStatename() {
            return _Statename;
        }
        public String getStateAbrivation() {
            return _StateAbrivation;
        }
    }
  • 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-28T04:28:26+00:00Added an answer on May 28, 2026 at 4:28 am

    Not sure, just doing this off the top of my head but, in your USAState class override your toString method.As is it maybe that the adapter is using the default toString() hence your weird text displaying (which I presume is the class name of the USAStates class)

    for example

    @Override
    public String toString(){
    return _Statename
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wrote code to display any type of file like pdf,svg,etc.But unfortunately my code
I wrote this code I have these errors Cannot implicitly convert type x.Program.TreeNode' to
i wrote following code to create a linkbutton programmatically, but its showing like lable
I wrote following code...but i am getting Error like: Error 1 'LoginDLL.Class1.Login(string, string, string)':
I wrote code in C# for ASP.Net website , but when i select one
I initially wrote code to build a form dynamically, based on data from the
I select item from spinner but this item can't select and show. Help me
I try to wrote code that read data from stdin: size_t bufSize = 1024;
i have problem in javascript email validation, I wrote code something like, //emp.php <form
I wrote code like: + (CGFloat)tableView:(UITableView*)tableView rowHeightForObject:(id)item { CustomTTTableSubtitleItem* captionedItem = item; CGFloat maxWidth

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.