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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:36:12+00:00 2026-05-23T12:36:12+00:00

I have a array list like this: private ArrayList<Locations> Artist_Result = new ArrayList<Location>(); This

  • 0

I have a array list like this:

private ArrayList<Locations> Artist_Result = new ArrayList<Location>();

This Location class has two properties: id and location.

I need to bind my ArrayList to a spinner. I have tried it this way:

Spinner s = (Spinner) findViewById(R.id.SpinnerSpcial);
ArrayAdapter adapter = new ArrayAdapter(this,android.R.layout.simple_spinner_item, Artist_Result);
s.setAdapter(adapter);

However, it shows the object’s hexadecimal value. So I think I have to set display the text and value for that spinner controller.

  • 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-23T12:36:13+00:00Added an answer on May 23, 2026 at 12:36 pm

    The ArrayAdapter tries to display your Location-objects as strings (which causes the Hex-values), by calling the Object.toString()-method. It’s default implementation returns:

    […] a string consisting of the name of the class of which the object
    is an instance, the at-sign character `@’, and the unsigned
    hexadecimal representation of the hash code of the object.

    To make the ArrayAdadpter show something actually useful in the item list, you can override the toString()-method to return something meaningful:

    @Override
    public String toString(){
      return "Something meaningful here...";
    }
    

    Another way to do this is, to extend BaseAdapter and implement SpinnerAdapter to create your own Adapter, which knows that the elements in your ArrayList are objects and how to use the properties of those objects.

    [Revised] Implementation Example

    I was playing around a bit and I managed to get something to work:

    public class Main extends Activity {
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            // Create and display a Spinner:
            Spinner s = new Spinner(this);
            AbsListView.LayoutParams params = new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.FILL_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT
            );
            this.setContentView(s, params);
            // fill the ArrayList:
            List<Guy> guys = new ArrayList<Guy>();
            guys.add(new Guy("Lukas", 18));
            guys.add(new Guy("Steve", 20));
            guys.add(new Guy("Forest", 50));
            MyAdapter adapter = new MyAdapter(guys);
            // apply the Adapter:
            s.setAdapter(adapter);
            // onClickListener:
            s.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
                /**
                 * Called when a new item was selected (in the Spinner)
                 */
                public void onItemSelected(AdapterView<?> parent,
                                           View view, int pos, long id) {
                    Guy g = (Guy) parent.getItemAtPosition(pos);
                    Toast.makeText(
                            getApplicationContext(),
                            g.getName()+" is "+g.getAge()+" years old.",
                            Toast.LENGTH_LONG
                    ).show();
                }
    
                public void onNothingSelected(AdapterView parent) {
                    // Do nothing.
                }
            });
        }
    
        /**
         * This is your own Adapter implementation which displays
         * the ArrayList of "Guy"-Objects.
         */
        private class MyAdapter extends BaseAdapter implements SpinnerAdapter {
    
            /**
             * The internal data (the ArrayList with the Objects).
             */
            private final List<Guy> data;
    
            public MyAdapter(List<Guy> data){
                this.data = data;
            }
    
            /**
             * Returns the Size of the ArrayList
             */
            @Override
            public int getCount() {
                return data.size();
            }
    
            /**
             * Returns one Element of the ArrayList
             * at the specified position.
             */
            @Override
            public Object getItem(int position) {
                return data.get(position);
            }
    
            @Override
            public long getItemId(int i) {
                return i;
            }
            /**
             * Returns the View that is shown when a element was
             * selected.
             */
            @Override
            public View getView(int position, View recycle, ViewGroup parent) {
                TextView text;
                if (recycle != null){
                    // Re-use the recycled view here!
                    text = (TextView) recycle;
                } else {
                    // No recycled view, inflate the "original" from the platform:
                    text = (TextView) getLayoutInflater().inflate(
                            android.R.layout.simple_dropdown_item_1line, parent, false
                    );
                }
                text.setTextColor(Color.BLACK);
                text.setText(data.get(position).name);
                return text;
            }
    
    
        }
    
        /**
         * A simple class which holds some information-fields
         * about some Guys.
         */
        private class Guy{
            private final String name;
            private final int age;
    
            public Guy(String name, int age){
                this.name = name;
                this.age = age;
            }
    
            public String getName() {
                return name;
            }
    
            public int getAge() {
                return age;
            }
        }
    }
    

    I fully commented the code, if you have any questions, don’t hesitate to ask them.

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

Sidebar

Related Questions

I have an array list of objects in my application. private static ArrayList<Player> userList=new
I have created a JSON object like this: static ArrayList<item> list = new ArrayList<item>();
I have a string like this: TEST.DATA.Data.COR.Point,2;TEST.DATA.Data.COR.Point,5;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.Point,12;TEST.DATA.Data.COR.WordTOFIND,18 I have a list of array with
I have a problem with ArrayList. I'm using ArrayList like this: private ArrayList<Playlist> mPlaylists;
I have a problem with comparing two arraylist, my first arraylist looks like this:
Hi I have an array list which has some numbers in it like {23,16,45,26,2,5,9}
I have class like this: public class Class1 { private String result; private String
If I have a method like this private void setStringList(List<String> aList) { ... }
I have a list comprehension operating on elements of an .NET array like obj.arr
I have an ArrayList<String> that I'd like to return a copy of. ArrayList has

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.