我正在开发一个应用程序,其中包含一个票证列表,有用户的添加票证和删除票证选项。添加选项工作正常,但删除选项不起作用,这是票证列表代码
public class TicketList {
private List<Ticket> ticketList;
public TicketList() {
ticketList = new ArrayList<>();
}
public List<Ticket> getTicketList() {
return ticketList;
}
public void setTicketList(List<Ticket> ticketList) {
this.ticketList = ticketList;
}
public void addTicketToList(Ticket ticket) {
ticketList.add(ticket);
}
public void removeFromList(Ticket ticket) {
ticketList.remove(ticket);
}
@Override
public String toString() {
return "TicketList{" + "ticketList=" + ticketList + '}';
}
}
另一个活动中的删除函数不起作用:
private void deleteTicket() {
TicketList ticketList = MyPreferencesManager.getInstance(this).getTicketList();
Ticket ticket = MyPreferencesManager.getInstance(this).getTicket();
ticketList.removeFromList(ticket);
MyPreferencesManager.getInstance(this).putTicketList(ticketList);
}
虽然 add 函数工作正常:
private void saveTicket() {
TicketList ticketList = MyPreferencesManager.getInstance(this).getTicketList();
Ticket ticket = new Ticket();
ticket.setUsername(username.getText().toString());
ticket.setPassword(password.getText().toString());
ticketList.addTicketToList(ticket);
MyPreferencesManager.getInstance(this).putTicketList(ticketList);
}
谁能告诉我删除或删除功能有什么问题?
皈依舞
相关分类