onBindViewHolder內(nèi)View綁定data。供回調(diào)使用
更新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);