购物车删除逻辑
来源:13-4 购物车事件逻辑梳理与实现-2
慕斯2943298
2019-01-23
final List data = shopCartAdapter.getData();
//要删除的数据
final List deleteEntities = new ArrayList<>();
for (MultipleItemEntity entity : data) {
final boolean isSelected = entity.getField(ShopCartItemFields.IS_SELECTED);
if (isSelected) {
deleteEntities.add(entity);
}
}
for (MultipleItemEntity entity : deleteEntities) {
int removePosition;
final int entityPosition = entity.getField(ShopCartItemFields.POSITION);
if (entityPosition > mCurrentCount - 1) {
removePosition = entityPosition - (mTotalCount - mCurrentCount);
} else {
removePosition = entityPosition;
}
if (removePosition <= shopCartAdapter.getItemCount()) {
shopCartAdapter.remove(removePosition);
mCurrentCount = shopCartAdapter.getItemCount();
//更新数据
shopCartAdapter.notifyItemRangeChanged(removePosition, shopCartAdapter.getItemCount());
}
}
这个地方删除,我代码都copy了还是出现部分item删除不了 removePosition = entityPosition - (mTotalCount - mCurrentCount);为什么要这样写呢,total好像一直0没有赋值过,相当于remove就是entity+mcuurent了,就出现部分删除不到,我尝试把total去掉,一个一个还可以删完,多选几个删就越界了,这块逻辑有点绕我画图罗列都没理清楚,麻烦老师在讲解下呢
2回答
-
傅猿猿
2019-01-24
1289151224
00 -
傅猿猿
2019-01-24
我后来简化了,视频还没出,要不这样,你加我微信我单独发你
012019-01-29
相似问题