RecyclerView - 获取所有现有的视图/查看器 [英] RecyclerView - get all existing views/viewholders
问题描述
我想在显示数据时更新 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屋!