A simple and elegant way to do this if you know the type of objects that the counter stores:
public class User { private Integer id; private String name; @Override public String toString() { return name; } }
Given the last class and the Spinner containing the User list, you can do the following:
public List<User> retrieveAllItems(Spinner theSpinner) { Adapter adapter = theSpinner.getAdapter(); int n = adapter.getCount(); List<User> users = new ArrayList<User>(n); for (int i = 0; i < n; i++) { User user = (User) adapter.getItem(i); users.add(user); } return users; }
It helps me! Hope he does it for you!
source share