简体   繁体   English

回顾onBindViewHolder向上滚动Recycler视图

[英]Recalling onBindViewHolder on scrolling up the Recycler view

I have list of images in my Recycler View and on scrolling down the recycler view, onBindViewHolder is called. 我在Recycler View中有图像列表,在向下滚动Recycler视图时,会调用onBindViewHolder。

I want to call onBindViewHolder again when I scroll up the recycler view so that I can get the position of currently viewed image. 当我向上滚动回收器视图时,我想再次调用onBindViewHolder,以便我可以获得当前查看图像的位置。

How to call onBindViewHolder again(on scrolling up)? 如何再次调用onBindViewHolder(向上滚动)?

That might not be the best way to figure out the currently viewed image, however you can add a scroll listener to your recycler view and whenever the dy scroll is negative you can call adapter.notifyDataSetChanged, so onBindViewHolder is called again 这可能不是找出当前查看图像的最佳方法,但是您可以向回收器视图添加滚动侦听器,每当dy滚动为负时,您可以调用adapter.notifyDataSetChanged,因此再次调用onBindViewHolder

   mFragmentListBinding.movieGrid.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (dy < 0) {
                   mAdapter.notifyDataSetChanged();
                }
            }
        });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM