onBindViewHolder内View绑定data。供回调使用
更新Adapter时可用下面的API
DiffUtil.DiffResult result = DiffUtil.calculateDiff(new DiffUtil.Callback() { @Override public int getOldListSize() { return mProductList.size(); } @Override public int getNewListSize() { return productList.size(); } @Override public boolean areItemsTheSame(int oldItemPosition, int newItemPosition) { return mProductList.get(oldItemPosition).getId() == productList.get(newItemPosition).getId(); } @Override public boolean areContentsTheSame(int oldItemPosition, int newItemPosition) { Product product = productList.get(newItemPosition); Product old = productList.get(oldItemPosition); return product.getId() == old.getId() && Objects.equals(product.getDescription(), old.getDescription()) && Objects.equals(product.getName(), old.getName()) && product.getPrice() == old.getPrice(); } }); mProductList = productList; result.dispatchUpdatesTo(this);
网友评论