RecyclerView 莫名奇妙自动滚动的问题
RecyclerView的Adapter里面有8个item。一旦下图中的“王三干杂”在上半部部分的时候,我点击最后四个中的任何一个的时候,图中的“王三干杂”自动滚动到中间去了。
class CartGoodsViewHolder extends RecyclerView.ViewHolder {
@Bind(R.id.iv_goods)
SimpleDraweeView goodsImg;
@Bind(R.id.tv_goods_name)
TextView goodsTitle;
@Bind(R.id.tv_price)
TextView goodsPrice;
@Bind(R.id.et_goods_number)
AddAndSubView goodsQuantities;
@Bind(R.id.cb_select_goods)
CheckBox goodsSelected;
@Bind(R.id.iv_delete_goods)
ImageView ivDeleteGoods;
@Bind(R.id.rl_goods)
RelativeLayout rlGoods;
public CartGoodsViewHolder(View itemView) {
super(itemView);
try {
ButterKnife.bind(this,itemView);
} catch (Exception e) {
e.printStackTrace();
}
goodsSelected.setOnClickListener(v->EventBus.getDefault()
.post(new GoodsSelectedEvent(orderModels.get(getAdapterPosition()).getGoodsId()
,orderModels.get(getAdapterPosition()).getShopId()
,goodsSelected.isChecked())));
}
}
在Fragment中调用notify方法:
@Override
public void notifyShoppingCartStatus(float totalValue) {
goodsAdapter.notifyDataSetChanged();
tvTotal.setText(String.valueOf(totalValue));
}
在presenter中遍历,查找哪些变化了:
@Subscribe
public void onGoodsSelected(GoodsSelectedEvent event) {
long totalValue = 0;
long goodsId = event.getGoodsId();
long shopId = event.getShopId();
boolean status = event.isSelected();
int selectedCount = 0;
int goodsCountInShop = 0;
int goodsCountAll = 0;
for(OrderModel item: orderModels) {
if(item.getGoodsId() == goodsId) {
item.setSelected(status);
}
if(item.getShopId() == shopId){
goodsCountInShop++;
if(item.isSelected()) {
selectedCount++;
}
}
if(item.isSelected()){
goodsCountAll++;
totalValue += item.getTotalValue();
}
}
for(OrderModel item: orderModels) {
if(item.getShopId() == shopId){
item.setShopSelected(goodsCountInShop == selectedCount);
}
}
EventBus.getDefault().post(new CheckAllStateChangeEvent(goodsCountAll == orderModels.size()));
view.notifyShoppingCartStatus(totalValue);
}
补充内容: 把recyclerview 高度设为match_parent就解决了.....
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论