Android RecyclerView更改所有项目图像视图
我有一些物品的回收视图。Android RecyclerView更改所有项目图像视图,android,listview,android-recyclerview,Android,Listview,Android Recyclerview,我有一些物品的回收视图。 我想更改项目上的所有ImageView图像(无滚动) 我在onBindViewHolder中的零件代码为: int count=parent.getChildCount(); v=父项。getChildAt(位置); while(i将每个视图从onBindViewHolder添加到ArrayList,然后循环此ArrayList并执行操作 ArrayList<ViewHolder> views = new ArrayList<>()
我想更改项目上的所有ImageView图像(无滚动)
我在onBindViewHolder中的零件代码为:
int count=parent.getChildCount();
v=父项。getChildAt(位置);
while(i将每个视图从onBindViewHolder添加到ArrayList,然后循环此ArrayList并执行操作
ArrayList<ViewHolder> views = new ArrayList<>();//call in the constructor make it a class variable so it can accessed globally;
现在,您可以在arraylist中循环并设置视图
int count = views.size();
for(int i=0; i<count; i++)
{
YourViewHolder v = views.get(i);
//call imageview from the viewholder object by the variable name used to instatiate it
ImageView imageView1 = v.imageViewFromHolder;
imageView1.setImageResource(R.mipmap.playsound);
LinearLayout linearSeek1 = v.linearLayoutFromHolder
linearSeek1.setVisibility(View.GONE);
}
int count=views.size();
对于(int i=0;i也许这有帮助.)
ViewGroup parent=(ViewGroup)holder.itemView.getParent();
对于(int i=0;i
RecyclerView在用户滚动时创建所有视图,并回收用户已滚动的视图(因此命名为RecyclerView)。您只能更新用户当前可见的视图。此外,您应该使用ViewHolder保存所有视图,并通过holder
实例访问这些视图(holder.imageview.setImageResource(…)。良好的阅读资料:-谢谢,我有一个完整的RecyclerView,它可以工作,但我有这个问题
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
views.add(holder)
}
int count = views.size();
for(int i=0; i<count; i++)
{
YourViewHolder v = views.get(i);
//call imageview from the viewholder object by the variable name used to instatiate it
ImageView imageView1 = v.imageViewFromHolder;
imageView1.setImageResource(R.mipmap.playsound);
LinearLayout linearSeek1 = v.linearLayoutFromHolder
linearSeek1.setVisibility(View.GONE);
}