购物车的删除逻辑有问题
来源:13-4 购物车事件逻辑梳理与实现-2
Marsor
2017-09-28
mTotalCount只是初始化了在后续的操作中没有赋值,当从前往后删除时实体的position与adapter中的位置并不一致
写回答
2回答
-
@OnClick(R2.id.tv_top_shop_cart_del) 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(ShopCartMultipleFields.IS_SELECTED); entity.setField(ShopCartMultipleFields.POSITION, i); if (isSelected){ deleteEntities.add(entity); } i++; } for (MultipleItemEntity entity : deleteEntities){ final int removePosition = entity.getField(ShopCartMultipleFields.POSITION); if (removePosition <= mAdapter.getItemCount()) { mAdapter.remove(removePosition); //更新数据 mAdapter.notifyItemRangeChanged(removePosition, mAdapter.getItemCount()); } } checkItemCount(); }
可以这样写
022017-10-01 -
zoro_
2018-03-13
@说的就是你傻冒 点击全选,再删 有问题.
00
相似问题