I'm trying to remove an object from an arraylist in java using android studio.
public class ToDoListManager {
private List<ToDoItem> items;
public ToDoListManager() {
items = new ArrayList<ToDoItem>();
items.add(new ToDoItem("Get Milk", false));
items.add(new ToDoItem("Walk the dog", true));
items.add(new ToDoItem("Go to the gym", false));
}
public List<ToDoItem> getItems() {
return items;
}
public void addItem(ToDoItem item) {
items.add(item);
}
public void removeItem(ToDoItem item) {
items.remove(item);
}
}
I've been calling the removeItem function from a keypress
When I add, let's say "test" to the array, it successfully adds it using items.add(item), however when I try items.remove(item) given the same string, it won't work.
It works if I do items.remove(1), but not if I do items.remove("test")
How could I fix this? I've tried many different ways. Thanks.