Android Bind Spinner to Class
Posted
by drbob
on Stack Overflow
See other posts from Stack Overflow
or by drbob
Published on 2010-03-18T04:02:10Z
Indexed on
2010/03/18
4:11 UTC
Read the original article
Hit count: 651
I'm having some trouble with the Spinner widget. Given the following code:
ArrayList<Person> people= new ArrayList<Person>();
Person = null;
for(int i = 0; i!= 10; i++) {
p = new Person();
s.setID(i);
s.setName("Name " + i);
people.add(s);
}
I'm using the following code to bind it to a Spinner:
Spinner spinner1 = (Spinner) findViewById (R.id.spinner);
ArrayAdapter<Person> adapter = new ArrayAdapter<Person>(this, android.R.layout.simple_spinner_item, people);
spinner1.setAdapter(adapter);
What I would like is for the value (id) to be hidden but passed when selected, and the name to appear. Any help is appreciated.
Thanks.
© Stack Overflow or respective owner