美文网首页
Google Sample Notes

Google Sample Notes

作者: hello_math | 来源:发表于2017-09-30 09:55 被阅读9次
    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);

    ViewModle

    相关文章

      网友评论

          本文标题:Google Sample Notes

          本文链接:https://www.haomeiwen.com/subject/xtrgextx.html