软件编程
位置:首页>> 软件编程>> Android编程>> Android 更新RecyclerView的好方法

Android 更新RecyclerView的好方法

作者:zhangmiao14  发布时间:2023-11-24 09:39:59 

标签:android,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);
     }
   }
 }

以上所述是小编给大家介绍的Android 更新RecyclerView的好方法网站的支持!

来源:http://www.cnblogs.com/zhangmiao14/archive/2017/06/13/7002272.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com