2
I have a Spinner in my Activity, need to make your items to be the names (field) of a Arraylist of objects, and that when selected, I be returned the id of the same to be able to perform a new operation.
For example:
My contact object
public class Contato {
String nome;
int id;
//getters e setters
}
I tried to do it this way, but in the Spinner is displayed only the address of the object in the application memory.
How can I have the name obtained from each object displayed on Spinner and return the id of the same?
// Uma lista contendo os objetos
ArrayList<Contact> contactlist= new ArrayList<Contact>();
contactlist.add("Gabe");
contactlist.add("Mark");
contactlist.add("Bill");
contactlist.add("Steve");
// Array Adapter que é definido como adapter do spinner
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_spinner_item, contactlist);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
Thank you very much! It worked perfectly.
– Rafael