zoukankan      html  css  js  c++  java
  • 更新RecyclerView的好方法

      一般在使用RecyclerView的时候不免要修改RecyclerView的数据,使用notifyDataSetChanged()来刷新界面,但是当数据比较多,而只是修改了一点的数据,或者刷新比较频繁,这样就会导致界面的卡顿问题,用户交互特别不好。

      这个时候就需要只是修改需要修改的数据,不要将数据全部进行更新,这样就可以解决问题。

      局部更新的代码如下:

      

    private int position;//当前recyclerview的position
    
    @BindView(R.id.speak_valuate_recycler_view)
    RecyclerView recyclerView;
    
    private LinearLayoutManager mRecyclerViewLayoutManager;
    
    mRecyclerViewLayoutManager = new LinearLayoutManager(this);
    mRecyclerViewLayoutManager.setOrientation(LinearLayoutManager.HORIZONTAL);
    recyclerView.setLayoutManager(mRecyclerViewLayoutManager);
    
    private void changVolume(final int volume) {
            int first = mRecyclerViewLayoutManager.findFirstVisibleItemPosition();
            int last = mRecyclerViewLayoutManager.findLastVisibleItemPosition();
    
            if (position >= first && position <= last) {
                View view = recyclerView.getChildAt(position - first);
                if (recyclerView.getChildViewHolder(view) instanceof SpeakContentAdapter.SpeakContentHolder) {
                    //修改数据
                    ProgressImageView progressImageView = (ProgressImageView) view.findViewById(R.id.speak_item_record);
                    progressImageView.setProgress(volume);
                }
            }
        }        
  • 相关阅读:
    重大技术需求系统八
    2020年下半年软考真题及答案解析
    周总结五
    重大技术需求系统七
    TextWatcher 编辑框监听器
    Android四大基本组件介绍与生命周期
    JAVA String,StringBuffer与StringBuilder的区别??
    iOS开发:保持程序在后台长时间运行
    宏定义的布局约束
    随便说一些
  • 原文地址:https://www.cnblogs.com/zhangmiao14/p/7002272.html
Copyright © 2011-2022 走看看