Glolita Glolita - 6 months ago 32
Android Question

Populating Android Spinner with List of Objects

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.

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

Here's my code:

User user1 = new User("user1",24);
User user2 = new User("user2",26);

// Creating adapter for spinner
List<User> users = new ArrayList<User>();

ArrayAdapter<User> dataAdapter = new ArrayAdapter<User>(this,
android.R.layout.simple_spinner_item, users);

// Drop down layout style - list view
// dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);

Spinner _EmpSpinner = null;
_EmpSpinner = (Spinner) findViewById(;

// attaching data adapter to spinner

And this is what it displays:


Try overriding toString() method in the User class:

public String toString() {