更新RecyclerView的好方法,更新recyclerview

來源:互聯網
上載者:User

更新RecyclerView的好方法,更新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);            }        }    }        

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.