title: Populating Android Spinner with List of Objects
body: <p>I'm populating my spinner with user object in order to work later with the user ID but the display of the user lists shows the address of the object I guess.</p>
  
  <p>So my question is how to display only one attribute of the object, in the case of user name, but still populate the spinner with the whole object</p>
  
  <h2>Here's my code:</h2>
  
  <pre class="lang-java prettyprint-override"><code>User user1 = new User("user1",24);
  User user2 = new User("user2",26);
  
  // Creating adapter for spinner
  List&lt;User&gt; users = new ArrayList&lt;User&gt;();
  users.add(user1);
  users.add(user2);
  
  ArrayAdapter&lt;User&gt; dataAdapter = new ArrayAdapter&lt;User&gt;(this, 
      android.R.layout.simple_spinner_item, users);
  
  // Drop down layout style - list view
  dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  // dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
  
  Spinner _EmpSpinner =  null;
  _EmpSpinner = (Spinner) findViewById(R.id.EmployeesSpinner); 
  
  // attaching data adapter to spinner
  _EmpSpinner.setAdapter(dataAdapter);
  </code></pre>
  
  <h2>And this is what it displays:</h2>
  
  <p><img src="https://i.stack.imgur.com/i8MjJ.png" alt=""></p>