Populate ListView from List<Object>

Viewed 20378

Basically I have a list of objects of class Ingredient which looks like this:

class Ingredient {
    public int id;
    public String name;

    public Ingredient(String name) {
        this.name = name;
    }
}

so each object from list have a name.

Now to use ArrayAdapter I need to have a List of strings filled with names. Is there any way to use ArrayAdapter with my list of Ingredients? This is how it looks right now

List<Ingredient> ingredientsList= new ArrayList<Ingredient>();
ingredientsList.add(new Ingredient("foo"));
ingredientsList.add(new Ingredient("bar"));
2 Answers
Related