不能使用list直接删除对象,要使用Iterator
Iterator<CouponsVO> iterator=viewModel.usedCoupons.get().iterator();
if(couponsVO.isChecked()){
viewModel.usedCoupons.get().add(couponsVO);
}else{
while (iterator.hasNext()) {
CouponsVO c = (CouponsVO) iterator.next();
if (couponsVO.getThqNO().equals(c.getThqNO())) {
iterator.remove();
}
}
//删除无效
//viewModel.usedCoupons.get().remove(couponsVO);
//viewModel.usedCoupons.notifyChange();
/* 会发生生ConcurrentModificationException异常
*for(CouponsVO c:viewModel.usedCoupons.get()){
* if(c.getThqNO().equals(couponsVO.getThqNO())) viewModel.usedCoupons.get().remove(c);
}*/
网友评论