RecyclerView-获取所有现有视图/视图持有者 [英] RecyclerView - get all existing views/viewholders

查看:446
本文介绍了RecyclerView-获取所有现有视图/视图持有者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在显示数据时更新RecyclerView,在我的情况下,我显示带或不带标签的图像.

I want to update the RecyclerView while it's displaying data, in my case, I show images with or without labels.

默认情况下,我在创建视图支架时设置标签的可见性,这很好,但是我希望用户在显示RecyclerView时通过菜单更改标签的可见性,因此我想手动更新可见性RecyclerView中的所有现有视图.

Defaultly I set the visibility of the label when I create the view holder and that's fine, but I want the user to change the labels visibility through the menu while the RecyclerView is shown, so I want to manually update the visibility for all existing views in the RecyclerView.

我能以某种方式获取所有现有的Views吗?我需要所有的东西,不仅是可见的东西,而且我不希望以后回收的View不更新...

Can I somehow get all existing Views? I need all, not only the visible ones, I don't want that a later recycled View is not updated...

推荐答案

在适配器类中:

Boolean isVisible = false;

public CustomAdapter(boolean isVisible) {
    this.isVisible= isVisible;
}
    @Override
    public void onBindViewHolder(ViewHolder holder, final int position) {
     ...

         if (isVisible){
           //setVisibility(View.VISIBLE)
         }else{
         //setVisibility(View.INVISIBLE
         }
    }

public void updateVisibility(boolean newValue){
 isVisible= newValue;
}

Activity中要在其中实例化适配器的位置更新值:

In Activity where you want to update the value where the adapter is instantiated:

adapter.updateVisibility(false);
adapter.notifydataSetChanged();

这篇关于RecyclerView-获取所有现有视图/视图持有者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆