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屋!