@OnClick(R2.id.tv_top_shop_cart_remove_selected)
void onClickRemoveSelectedItem() {
final List<MultipleItemEntity> data = mAdapter.getData();
//要删除的数据
final List<MultipleItemEntity> deleteEntities = new ArrayList<>();
int i = 0;
for (MultipleItemEntity entity : data) {
final boolean isSelected = entity.getField(ShopCartItemFields.IS_SELECTED);
entity.setField(ShopCartItemFields.POSITION, i); //每次重新赋值位置
if (isSelected) {
deleteEntities.add(entity);
}
i++;
}
//从List中最后一个开始删除,防止引起下标的变动
for (int j = deleteEntities.size()-1; j >=0; j--) {
int removePosition = deleteEntities.get(j).getField(ShopCartItemFields.POSITION);
mAdapter.remove(removePosition); //remove方法内部调用notifyItemRangeChanged
}
//checkItemCount();
}
这个是我自己凑合写的。。:-D