当前位置: 首页 > news >正文

discuz 旅游网站模版/企业的网络推广

discuz 旅游网站模版,企业的网络推广,做淘宝相关网站,怎么买域名做企业网站DiffUtils实现partial bindData support-v7:24.2.0中出来的一个兼容工具,它用来比较两个数据集,寻找出旧数据集-》新数据集的最小变化量。 这个工具对于列表中需要局部内容发生变化是时,只需要计算出发生变化的部分,只刷新变化部…

                                                                               DiffUtils实现partial bindData

support-v7:24.2.0中出来的一个兼容工具,它用来比较两个数据集,寻找出旧数据集-》新数据集的最小变化量。

这个工具对于列表中需要局部内容发生变化是时,只需要计算出发生变化的部分,只刷新变化部分的内容,即可极大的提高刷新页面数据的效率问题。不必通过notifyDataSetChanged方法进行整个界面的刷新

DiffUtil的作用,就是找出集合中每一个Item发生的变化,然后对每个变化给予对应的刷新。

1.先看DiffUtil.Callback这个抽象内的源码入下:

/**
 * A Callback class used by DiffUtil while calculating the diff between two lists.
 */
public abstract static class Callback {/**
     * Returns the size of the old list.
     *
     * @return The size of the old list.
     */
    public abstract int getOldListSize();

    /**
     * Returns the size of the new list.
     *
     * @return The size of the new list.
     */
    public abstract int getNewListSize();

    /**
     * Called by the DiffUtil to decide whether two object represent the same Item.
     * <p>
     * For example, if your items have unique ids, this method should check their id equality.
     *
     * @param oldItemPosition The position of the item in the old list
     * @param newItemPosition The position of the item in the new list
     * @return True if the two items represent the same object or false if they are different.
     */
    public abstract boolean areItemsTheSame(int oldItemPosition, int newItemPosition);

    /**
     * Called by the DiffUtil when it wants to check whether two items have the same data.
     * DiffUtil uses this information to detect if the contents of an item has changed.
     * <p>
     * DiffUtil uses this method to check equality instead of {@link Object#equals(Object)}
     * so that you can change its behavior depending on your UI.
     * For example, if you are using DiffUtil with a
     * {@link android.support.v7.widget.RecyclerView.Adapter RecyclerView.Adapter}, you should
     * return whether the items' visual representations are the same.
     * <p>
     * This method is called only if {@link #areItemsTheSame(int, int)} returns
     * {@code true} for these items.
     *
     * @param oldItemPosition The position of the item in the old list
     * @param newItemPosition The position of the item in the new list which replaces the
     *                        oldItem
     * @return True if the contents of the items are the same or false if they are different.
     */
    public abstract boolean areContentsTheSame(int oldItemPosition, int newItemPosition);

    /**
     * When {@link #areItemsTheSame(int, int)} returns {@code true} for two items and
     * {@link #areContentsTheSame(int, int)} returns false for them, DiffUtil
     * calls this method to get a payload about the change.
     * <p>
     * For example, if you are using DiffUtil with {@link RecyclerView}, you can return the
     * particular field that changed in the item and your
     * {@link android.support.v7.widget.RecyclerView.ItemAnimator ItemAnimator} can use that
     * information to run the correct animation.
     * <p>
     * Default implementation returns {@code null}.
     *
     * @param oldItemPosition The position of the item in the old list
     * @param newItemPosition The position of the item in the new list
     *
     * @return A payload object that represents the change between the two items.
     */
    @Nullable
    public Object getChangePayload(int oldItemPosition, int newItemPosition) {return null;
    }
}

2.使用方法:

 1.新建一个类继承DiffUtil.Callback实现抽象方法(前4个必须,最后一个可选)

  2.

//比较新老数据的差异

DiffUtil.DiffResult diffResult = DiffUtil.calculateDiff(new DiffCallBack(mDatas, newDatas), true);
//然后利用DiffUtil.DiffResult对象的dispatchUpdatesTo()方法,传入RecyclerView的Adapter,替代mAdapter.notifyDataSetChanged()方法。
diffResult.dispatchUpdatesTo(mAdapter);
//将新数据添加适配器中
mMyAdapter.setList(newList);



举例说明:

需求:如下图:


 点击===》关注,实现点击条目的局部数据更新

  核心代码如下:

  DiffUtil.Callback的子类:


Adapter的代码


list_item.xml


MainActivity代码如下:



轻松实现列表数据的partial binddata~~~

http://www.jmfq.cn/news/4784743.html

相关文章:

  • 泉州手机模板建站/营销培训讲师
  • wordpress 图片比例/互联网关键词优化
  • wordpress顶部滑动/搜索引擎优化关键词
  • 网站的开发方法/站长seo工具
  • django做的购物网站/推广普通话手抄报简单又好看内容
  • au网站怎么注册/2024年8月爆发新的大流行病毒吗
  • 长沙广告网页设计最新招聘信息/seo站长网怎么下载
  • 移动外贸网站建设/长沙专业seo优化推荐
  • 仿一个展示型网站多少钱/企业网络组网设计
  • 做摄影网站的目的是什么/搜狐财经峰会
  • 学做网站好吗/北京seo公司哪家好
  • vps如何做网站/如何进行seo
  • 可以做众筹的网站有哪些/优化网站广告优化
  • 哪里做百度网站/上海做网络口碑优化的公司
  • 青岛建设网站制作/外贸推广平台哪个好
  • 如东住房和城乡建设局网站/seo推广哪家公司好
  • 电子商务网站建设实训个人总结/品牌营销策划方案怎么做才好
  • 常德网站建设费用/外贸营销网站制作
  • 宁波外包seo服务/网站推广和seo
  • 做网站的经验和体会/搜索引擎关键词优化方案
  • 济南网站制作工具/互联网营销师证书有用吗
  • 效果好的网站建设公司/惠州网络营销
  • 网站开发语言java和php/宁波seo网络推广外包报价
  • 广州企业网站建设推荐/seo推广怎么样
  • wordpress当下载站/国外域名注册网站
  • 做一款微信小程序多少钱/长春seo公司
  • 网站建设对于电子商务的意义/唐山网站建设方案优化
  • 做衣服的网站推荐/济南优化网页
  • php零基础做网站/郑州黑帽seo培训
  • 长春网站建长春做网站/外链的作用